Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

For making fields read only for the existing record

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi Team,

Can anyone help me out for getting the Javascript code for making the fields read only when the existing record is opened?

Below is my code but its not working:

function DisableFields() {
debugger;
var kvsl_value;
var kvsl_key;
var value = Xrm.Page.ui.controls.get("kvsl_value");
var value = Xrm.Page.ui.controls.get("kvsl_key");
if (kvsl_value != null && kvsl_key != null) {
value.setDisabled(true);
key.setDisabled(true);
}
else {
value.setDisabled(false);
key.setDisabled(false);
}
}

Thanks in Advance,

Anita

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: For making fields read only for the existing record

    Thanks guys. It worked fine with the JS and BR.

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: For making fields read only for the existing record

    I would suggest instead of writing code ,you can implement OOB form  business Rule in your form when the fields contains data condition.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: For making fields read only for the existing record

    Hi,

    You can try this.

    else

    {

    var value = Xrm.Page.ui.controls.get("kvsl_value");

    value.setVisible(false);

    var key = Xrm.Page.ui.controls.get("kvsl_key");

    key.setVisible(false);

    }

    Thanks

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: For making fields read only for the existing record

    Guys,

    The code worked fine but gets failed on the negative scenarios like even for the new form the fields are read only. The else condition of the code does not work  or being skipped.

    Please help me out for this. Have done a debugging also but unable to rectify the issue.

    Thanks,

    Anita

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: For making fields read only for the existing record

    Better to debug your code to see what's causing this issue.

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: For making fields read only for the existing record

    Hi Anita,

    Cross check the folowing.

    1. You have added the two fields key and value to the form.

    2. The logical names of these fields are correct.

    Hope this helps.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: For making fields read only for the existing record

    Hi anita,

    You will get this error, if the field is not available or the schema name is different.

    Thanks

  • ZickQian Profile Picture
    ZickQian 20 on at
    RE: For making fields read only for the existing record

    Hi, 

    The script error shows you are not passing right field name in your script. Double click the field on your form, use the "Name" field in details tab in your script. 

    The actual name of your fields may not be "kvsl_value" , or "kvsl_key" , 

    7411.crm1.png

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: For making fields read only for the existing record

    Hi Guys,

    I have used all the solutions provided above but still getting the script error. Please see the screenshot attached.6811.scripterror.png

    Please help me out to resolve this.

    Thanks in Advance,

    Anita

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: For making fields read only for the existing record

    Make sure to apply your logic when FormType is 2

    msdn.microsoft.com/.../gg327828.aspx

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans