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

Announcements

News and Announcements icon
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,628 on at

    Hi,

    are you referring to editable grid view?

  • naZir Profile Picture
    850 on at

    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,628 on at

    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,628 on at

    Hi,

    you also can refer to below post.

    community.dynamics.com/.../780226

  • Suggested answer
    Pawar Pravin Profile Picture
    5,237 on at

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
RichardM Profile Picture

RichardM 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans