web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Make a record Read Only dynamically

(0) ShareShare
ReportReport
Posted on by 850

Hi I am trying to make a record read only in some specific condition.

I am able to make all fields read only but unable to do the same for grid Views in that form

Here is my code

function makingAllFieldreadOnly() {
debugger;
var statusValue = Xrm.Page.getAttribute("statuscode").getValue();
if (statusValue == 4) {
var controls = Xrm.Page.ui.controls.get();
for (var i in controls) {
var control = controls[i];
if (i == 10 || i == 11 || i == 12 || i == 21 || i == 22 || i == 26) {//To avoid GridView

}
else {
try {
if (control) {
control.setDisabled(true);
}
}
catch (e) {
alert(e.message + "");
}
}
}
}
else {
var controls = Xrm.Page.ui.controls.get();
for (var i in controls) {
var control = controls[i];
if (i == 10 || i == 11 || i == 12 || i == 21 || i == 22 || i == 26) {//To avoid GridView

}
else {
try {
if (control) {
control.setDisabled(false);
}
}
catch (e) {
alert(e.message + "");
}
}
}
}
}

Is there any supported way to amke grid view also read only..(Please Note:-I dont want to use RBW)

*This post is locked for comments

I have the same question (0)
  • Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Make a record Read Only dynamically

    Hi,

    are you referring to editable grid view?

  • naZir Profile Picture
    850 on at
    RE: Make a record Read Only dynamically

    Yes  ..What would be the scenario for editable grid view. for normal i can do it by writing Enable Rule

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Make a record Read Only dynamically

    Hi Nazir,

    please refer to below post

    community.dynamics.com/.../know-how-editable-grid-disable-fields-conditionally-using-javascript-dynamics-crm-d365-d365-editablegrid-1

    you need to use context.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Make a record Read Only dynamically

    Hi,

    you also can refer to below post.

    community.dynamics.com/.../780226

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: Make a record Read Only dynamically

    Hi Nazir,

    You can use below code to make all fields as read only.

    function setFieldsDisabled(context) {

       var name = Xrm.Page.getAttribute("name").getValue();

       if (name == "DisableFields") {

           var contact = context.getFormContext().data.entity;

           contact.attributes.forEach(function(field, i) {

               field.controls.get(0).setDisabled(true);

           });

       }

    }

    Also make sure that if you need to lock fields of header fields.

    If that is case please do use below code.

    Xrm.Page.getControl("header_logicalnameofattribute").setDisabled(true);

    Regards,

    Pravin

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans