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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Disable an HTML control in HTML web resource inserted on a Microsoft Dynamics CRM 2013 entity form after saving the form

(0) ShareShare
ReportReport
Posted on by

Hi,

I have added an HTML web resource (containing an option set field) on one of the custom entities form. I want to disable the field (that is option set or drop-down list on the HTML web resource) when a new form is saved. That means the field will only remain enabled for a new form and will get disabled as soon as the form is saved and will remain disabled further. I have written JavaScript code on load of the entity form to keep the field enabled for "New" form and disable it for "Update" form.

The field is not getting disabled when a new record for the entity is saved. Because, in CRM 2013, the form does not get refreshed after saving it and hence the OnLoad event does not get triggered.

Any idea how to solve this issue?

*This post is locked for comments

I have the same question (0)
  • NatrajY Profile Picture
    3,040 on at

    If the form is not refreshed after save, can't you just disable the field in the save event as well? If the save event has completed successfully then it is a update form.

  • Community Member Profile Picture
    on at

    Thanks Natraj.

    Is there any way to disable an HTML control in the HTML web resource inserted on crm entity form through java script written on save of the entity form?

  • Verified answer
    Deepesh161 Profile Picture
    6,317 on at
  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at

    Hi Purva,

    try this code on your form load, and make necessary changes in control Id,

    function DisableHTMLWebresouceControl()
    {
    //Get HTML web resource control
     var webRefCtrl = Xrm.Page.getControl('Your web resource ID from form').getObject();
     
     //web resource HTML document
     var htmlDoc=webRefCtrl.contentDocument;
     
     //get list of controls by tag name
     var ctrlList = htmlDoc.getElementsByTagName('select');
     
     //get list of controls by Id
     var ctrlById= doc.getElementById('textCtrl');
    
     //If web resource is not loaded yet, then call same function after some time. 
      if(ctrlList[0]==null)
      {
         setTimeout(DisableHTMLWebresouceControl,1000)
         return;
      }
      
     // disable control in HTML web resource. 
     ctrlList[0].disabled =true;
    }


    This code is disabling HTML web resource control from Form script.. I dont know this is supported or not because web are using DOM, but using DOM we are not modifying CRM form, we are modifying   web resource

    check 

    https://msdn.microsoft.com/en-us/library/gg334266.aspx#BKMK_getControlType

    Hope this will helps you to solve your problem. 

    Thanks, 

  • Community Member Profile Picture
    on at

    Thanks Deepesh and Mahadeo.

    The solution provided by both of you works for me.

    Also, "Xrm.Page.ui.controls.get('WebResource_Name')" and " Xrm.Page.getControl('WebResource_Name')" methods are not supported by Microsoft Dynamics CRM Online. Hence, both the solutions work for Microsoft Dynamics RM 2013 on-premises only.

    Is there any way to support the functionality for Microsoft Dynamics CRM Online as well?

  • Dynamics 365 CRM Profile Picture
    185 on at

    Hi...Does you issue resolved. i am also facing same issue.I am using dynamics 365 crm online . Below code is not working when I am trying to disable a section onchange of a field. (Note : There is a HTML webresource in the section.That webreource is a button) 

    var ctrlName = Xrm.Page.ui.controls.get();

    for (var i in ctrlName) {

    var ctrl = ctrlName[i];

    var ctrlSection = ctrl.getParent().getName();

    if (ctrlSection == "tab_3_section_2") {

    ctrl.setDisabled(true);

    }
    }

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans