locked
Calling an action on cliking a button from main grid,ms crm 2013 online RRS feed

  • Question

  • Hi All,

    I have a requirement to call an action from button click on the main grid of report entity. The action is designed for creating a record in an custom entity with fields as input arguments declared.

    I tried the following Jscript, no errors but record does not gets created as well(Action not called)

    function ReadSelectedSubGridRecords() {

        debugger;

        if (document.getElementById("crmGrid")) {

            var grid = document.getElementById("crmGrid").control;

            for (var rowNo = 0; rowNo < grid.get_selectedRecords().length; rowNo++)

                var result = grid.get_selectedRecords()[rowNo].Name;

            alert(result);

            sample(result);

        }

    }

    function sample(result) {

        var ProjectName = result;

        //var entityId = Xrm.Page.data.entity.getId();

        var entityName = "contact";

        var requestName = "new_create_appointment";

        Testtask(ProjectName, entityName, requestName);

    }

     

    function Testtask(ProjectName, entityName, requestName) {

        // Creating the request XML for calling the Action

        var requestXML = ""

        requestXML += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";

        requestXML += "  <s:Body>";

        requestXML += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";

        requestXML += "      <request xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";

        requestXML += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";

        requestXML += "          <a:KeyValuePairOfstringanyType>";

        requestXML += "            <b:key>Target</b:key>";

        requestXML += "            <b:value i:type=\"a:EntityReference\">";

        //requestXML += "              <a:Id>" + entityId + "</a:Id>";

        requestXML += "              <a:LogicalName>" + entityName + "</a:LogicalName>";

        requestXML += "              <a:Name i:nil=\"true\" />";

        requestXML += "            </b:value>";

        requestXML += "          </a:KeyValuePairOfstringanyType>";

        requestXML += "          <a:KeyValuePairOfstringanyType>";

        requestXML += "            <b:key>ProjectName</b:key>";

        requestXML += "            <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" + ProjectName + "</b:value>";

        requestXML += "          </a:KeyValuePairOfstringanyType>";

        requestXML += "        </a:Parameters>";

        requestXML += "        <a:RequestId i:nil=\"true\" />";

        requestXML += "        <a:RequestName>" + requestName + "</a:RequestName>";

        requestXML += "      </request>";

        requestXML += "    </Execute>";

        requestXML += "  </s:Body>";

        requestXML += "</s:Envelope>";

        var req = new XMLHttpRequest();

        req.open("POST", GetClientUrl(), false)

        req.setRequestHeader("Accept", "application/xml, text/xml, */*");

        req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

        req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");

        req.send(requestXML);

        alert("hi");

        //Get the Resonse from the CRM Execute method

        //var response = req.responseXML.xml;

    }

    function GetClientUrl() {

        if (typeof Xrm.Page.context == "object") {

            clientUrl = Xrm.Page.context.getClientUrl();

        }

        var ServicePath = "/XRMServices/2011/Organization.svc/web";

        return clientUrl + ServicePath;

    }

     Kindly help me.


    Regards, Rekha.J

    Wednesday, April 29, 2015 1:02 PM

All replies

  • Hi All,

    Any help on this?


    Regards, Rekha.J

    Thursday, April 30, 2015 4:54 AM