locked
MS CRM 2013 Recalculate Button by using JS RRS feed

  • Question

  •  If we enter the values in Tax field for selected Contacts it should Create & Update in Account record by clicking Recalculate button by using JAVA SCRIPT
    Wednesday, January 29, 2014 5:08 AM

All replies

  • Hi frnds,

    This is the sample code for above question 

    function hi()

    {
    debugger;
    var guid = Xrm.Page.data.entity.getId().replace('{', '').replace('}', '');
    //alert(guid);


    var serverPath = location.protocol + "//" + location.host + "/";

                var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

                var oDataPath = serverPath + ODATA_ENDPOINT + "/ContactSet?";


                 oDataPath += "$select=*&$filter=ParentCustomerId/Id eq guid'" + guid + "'" + "&";

                //var orderby = "$orderby=CreatedOn desc";
                //oDataPath += orderby;
                //223550001

                var retrieveRecordsReq = new XMLHttpRequest();
                retrieveRecordsReq.open('GET', oDataPath, false);
                retrieveRecordsReq.setRequestHeader("Accept", "application/json");
                retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8")
                retrieveRecordsReq.send(null);
                var retrievedAccounts = JSON.parse(retrieveRecordsReq.responseText).d;
                var jsonResult = retrievedAccounts.results;


      var val=0;

                for (var i = 0; i < jsonResult.length; i++)
     {

                    if(jsonResult[i].new_Tax!=null)

           {                             
                        val =val+parseInt(jsonResult[i].new_Tax);
                                  
                    }

                }
           
    var total = val;

    Xrm.Page.data.entity.attributes.get("new_totaltax").setValue(total.toString()); 
        
    }

    Wednesday, January 29, 2014 5:10 AM