Wednesday, 10 July 2013

Get Html Webresource control value in Crm 2011 javascript


Here "WebResource_CboComponent" is webresource name and "CboComponent" is html control name in the html page.

the html page looks like below

<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE></TITLE><LINK rel=stylesheet type=text/css href="/_common/styles/fonts.css.aspx?lcid=1033"><LINK rel=stylesheet type=text/css href="/_common/styles/global.css.aspx?lcid=1033"><LINK rel=stylesheet type=text/css href="/_common/styles/select.css.aspx?lcid=1033">
<SCRIPT type=text/javascript src="../ClientGlobalContext.js.aspx"></SCRIPT>

<SCRIPT type=text/javascript src="json2.js"></SCRIPT>

<SCRIPT type=text/javascript src="jquery161min.js"></SCRIPT>

<SCRIPT type=text/javascript src="FetchXMLUtil.js"></SCRIPT>
<SCRIPT type=text/javascript src="XrmServiceToolkit.js"></SCRIPT>

<SCRIPT type=text/javascript src="../New_chargeitem_main_library.js"></SCRIPT>

<SCRIPT language=javascript type=text/javascript>

    var Quantity = 0;
    function window.onload() {
        //alert("Onload");
        var _oServices;
        var _sServerUrl = GetGlobalContext().getServerUrl();
       
        var new_chargeid = window.parent.Xrm.Page.getAttribute("new_chargeid").getValue();
     
        var fFetch = "fetch Query";
         _oServices = new FetchUtil(_sServerUrl);
        var oEntity = _oServices.Fetch(fFetch, ComponentsCallBack);
    }
    function ComponentsCallBack(results) {


        var _lookupItems = new Array();
        document.getElementById("CboComponent").length = 0;
        if (results.length != 0) {
            var Select = document.getElementById("CboComponent");
            for (i = 0; i < results.length; i++) {

                option = document.createElement("option");
                option.text = results[i].attributes.new_name.value;
                option.value = results[i].attributes.new_componentid.value.toLowerCase();
                option.title = "Components";
                Select.add(option, i);
            }

            // Select.selectedIndex = -1;
            var lookup = new Array();

             lookup = window.parent.Xrm.Page.getAttribute("new_componentid").getValue();
             if (Select != null && lookup != null) {
                 var id = lookup[0].id.toLowerCase().replace('{', '').replace('}', '');
                 Select.value = id;
                 //window.parent.GetComponentRecord(id);
                 window.parent.GetInclusiveQuantity();
               }else {
                 Select.selectedIndex = -1;
            }

          
        }
    }
 
   function addComponent() {
        //alert("On change Event");
        var Select = document.getElementById("CboComponent");
        if (Select !=null && Select.selectedIndex >= 0) {
            var compID = Select.options[Select.selectedIndex].value;
           
            if (compID != null) {
               var unitprice = window.parent.Xrm.Page.getAttribute("new_componentunitprice");
                if (unitprice != undefined)
                    unitprice.setValue(null);
                window.parent.GetComponentRecord(compID);
               
            }
        }

    }

    function ComponentLookup() {
       // alert("ComponentLookup");
        window.parent.document.getElementById('new_componentid').click();

    }

  </SCRIPT>

<META charset=utf-8></HEAD>
<BODY>
<TABLE cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD style="WIDTH: 100%"><SELECT style="WIDTH: 100%" id=CboComponent onchange=addComponent()  class=ms-crm-SelectBox></SELECT> </TD>
</TR></TBODY></TABLE>

</BODY></HTML>


 In the Entity form load(where we used the above html page as webresource in the form) we can access the control from below code

function ToggleFormFields(disable) {
var Select = Xrm.Page.getControl("WebResource_CboComponent").getObject().
contentWindow.window.document.getElementById("CboComponent");

   if(Select!=null)
        Select.disabled =disable;

}


No comments:

Post a Comment