Sunday, November 22, 2015

Access a html webresource control from javascript webresource

Access a html webresource control from javascript webresource

If you have any doubt in the post please post comments. I will try to solve your problem.

To add html control in the CRM form. we have to create new html web resource and insert the html web resource in the form.

Some times we need to access html control from outside Java-script web resource.

Syntax:
var customHtml = Xrm.Page.ui.controls.get("WebResource Name");
if(customHtml!=null || customHtml!='')
var destination = customHtml.getObject().contentWindow.document;
if(destination!=null || destination!='')
var customControl = destination.getElementById("control name");

Example:
Disabled the html control from javascript webresource

var customHtml = Xrm.Page.ui.controls.get("WebResource_CarrierLookup");

if(customHtml!=null || customHtml!='')
var destination = customHtml.getObject().contentWindow.document;

if(destination!=null || destination!='')
var customControl = destination.getElementById("btnLookup");

if(customControl!=null || customControl!='')
customControl.disabled=false;

5 comments:

  1. Some times we need to access html control from outside Java-script web resource.psd to html5

    ReplyDelete
  2. Hi I am not able to access a button in html web resource (placed on a section in form) from javascript on form

    ReplyDelete
    Replies
    1. i have tried using the above code. no help.

      Delete
    2. May i know your requirement and what is your problem

      Delete
  3. I am trying to Hide Form Ribbon button(i.e Deactivate) based security role for that i have wrote JS script for getting role
    when i try to get the ribbon button ID, It is giving Null
    1) btnHide = document.getElementById("account|NoRelationship|Form|Mscrm.Form.account.SaveAndClose" + "_d");

    2) var objValue = Xrm.Page.getAttribute("account|NoRelationship|Form|Mscrm.Form.account.SaveAndClose");

    3) btnHide1 = window.top.document.getElementById("account|NoRelationship|Form|crm.Form.account.SaveAndClose");

    Above all are giving Null value.
    any idea

    ReplyDelete

Note: Only a member of this blog may post a comment.