admin管理员组

文章数量:1022695

I want to change statecode and statuscode on ribbon button click in CRM 2011. I have javascript function calling SOAP:

if (typeof (Smpl) == "undefined") { Smpl = {}; }

Smpl.Items = {
change: function () {

    var entityId = Xrm.Page.data.entity.getId().substr(1, 36);
    var entityName = Xrm.Page.data.entity.getEntityName();
    var entityState = 0;
    var entityStatus = 100007891;

    var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    "<soap:Envelope xmlns:soap='/' xmlns:xsi='' xmlns:xsd=''>" +
    "<soap:Body><Execute xmlns=''><Request xsi:type='SetStateDynamicEntityRequest'>" +
    "<Entity><Id xmlns=''>" + entityId + "</Id>" +
    "<Name xmlns=''>" + entityName + "</Name></Entity>" +
    "<State>" + entityState + "</State>" +
    "<Status>" + entityStatus + "</Status>" +
    "</Request></Execute></soap:Body></soap:Envelope>";

    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", ":80/web/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction", "");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);

    var resultXml = xHReq.responseXML;
    var errorCount = resultXml.selectNodes('//error').length;
    if (errorCount != 0) {
        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
        alert(msg);
    }
    window.location.reload();
  }
}

I'd say the whole code is okay, but of course, it's not working at all :/ On google I found just a few snippets, but nothing different from my code. Does not really nobody change status from the ribbon via javascript??

Thank you

I want to change statecode and statuscode on ribbon button click in CRM 2011. I have javascript function calling SOAP:

if (typeof (Smpl) == "undefined") { Smpl = {}; }

Smpl.Items = {
change: function () {

    var entityId = Xrm.Page.data.entity.getId().substr(1, 36);
    var entityName = Xrm.Page.data.entity.getEntityName();
    var entityState = 0;
    var entityStatus = 100007891;

    var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap/soap/envelope/' xmlns:xsi='http://www.w3/2001/XMLSchema-instance' xmlns:xsd='http://www.w3/2001/XMLSchema'>" +
    "<soap:Body><Execute xmlns='http://schemas.microsoft./crm/2007/WebServices'><Request xsi:type='SetStateDynamicEntityRequest'>" +
    "<Entity><Id xmlns='http://schemas.microsoft./crm/2006/CoreTypes'>" + entityId + "</Id>" +
    "<Name xmlns='http://schemas.microsoft./crm/2006/CoreTypes'>" + entityName + "</Name></Entity>" +
    "<State>" + entityState + "</State>" +
    "<Status>" + entityStatus + "</Status>" +
    "</Request></Execute></soap:Body></soap:Envelope>";

    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "http://my.full.:80/web/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft./crm/2007/WebServices/Execute");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);

    var resultXml = xHReq.responseXML;
    var errorCount = resultXml.selectNodes('//error').length;
    if (errorCount != 0) {
        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
        alert(msg);
    }
    window.location.reload();
  }
}

I'd say the whole code is okay, but of course, it's not working at all :/ On google I found just a few snippets, but nothing different from my code. Does not really nobody change status from the ribbon via javascript??

Thank you

Share Improve this question asked Oct 21, 2011 at 14:26 o..oo..o 1,9317 gold badges36 silver badges65 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 1

For changing state of an entity you need to use the EntityMoniker, in in plugins and also in JScript.

Try the code from the following link:

Set Status or State of a Record Using Jscript

I was surfing on the web, because a friend of mine had the same problem, I haven't changed de statecode in CRM 2011 via JScript, but I think I have your solution.

In case of my friend, he had statecode value in wrong format, he was using 0 or 1, and service was returning an error telling him, 0 or 1 weren't correct values of statecode, then I though, coding in C# you have to put in State a value from an Enumeration ('Active' or 'Inactive'), he changed his integer value to 'Active' and the soap call runs fine.

Report the real solution if you arrive to it :)

See you.

I want to change statecode and statuscode on ribbon button click in CRM 2011. I have javascript function calling SOAP:

if (typeof (Smpl) == "undefined") { Smpl = {}; }

Smpl.Items = {
change: function () {

    var entityId = Xrm.Page.data.entity.getId().substr(1, 36);
    var entityName = Xrm.Page.data.entity.getEntityName();
    var entityState = 0;
    var entityStatus = 100007891;

    var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    "<soap:Envelope xmlns:soap='/' xmlns:xsi='' xmlns:xsd=''>" +
    "<soap:Body><Execute xmlns=''><Request xsi:type='SetStateDynamicEntityRequest'>" +
    "<Entity><Id xmlns=''>" + entityId + "</Id>" +
    "<Name xmlns=''>" + entityName + "</Name></Entity>" +
    "<State>" + entityState + "</State>" +
    "<Status>" + entityStatus + "</Status>" +
    "</Request></Execute></soap:Body></soap:Envelope>";

    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", ":80/web/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction", "");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);

    var resultXml = xHReq.responseXML;
    var errorCount = resultXml.selectNodes('//error').length;
    if (errorCount != 0) {
        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
        alert(msg);
    }
    window.location.reload();
  }
}

I'd say the whole code is okay, but of course, it's not working at all :/ On google I found just a few snippets, but nothing different from my code. Does not really nobody change status from the ribbon via javascript??

Thank you

I want to change statecode and statuscode on ribbon button click in CRM 2011. I have javascript function calling SOAP:

if (typeof (Smpl) == "undefined") { Smpl = {}; }

Smpl.Items = {
change: function () {

    var entityId = Xrm.Page.data.entity.getId().substr(1, 36);
    var entityName = Xrm.Page.data.entity.getEntityName();
    var entityState = 0;
    var entityStatus = 100007891;

    var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap/soap/envelope/' xmlns:xsi='http://www.w3/2001/XMLSchema-instance' xmlns:xsd='http://www.w3/2001/XMLSchema'>" +
    "<soap:Body><Execute xmlns='http://schemas.microsoft./crm/2007/WebServices'><Request xsi:type='SetStateDynamicEntityRequest'>" +
    "<Entity><Id xmlns='http://schemas.microsoft./crm/2006/CoreTypes'>" + entityId + "</Id>" +
    "<Name xmlns='http://schemas.microsoft./crm/2006/CoreTypes'>" + entityName + "</Name></Entity>" +
    "<State>" + entityState + "</State>" +
    "<Status>" + entityStatus + "</Status>" +
    "</Request></Execute></soap:Body></soap:Envelope>";

    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "http://my.full.:80/web/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft./crm/2007/WebServices/Execute");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);

    var resultXml = xHReq.responseXML;
    var errorCount = resultXml.selectNodes('//error').length;
    if (errorCount != 0) {
        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
        alert(msg);
    }
    window.location.reload();
  }
}

I'd say the whole code is okay, but of course, it's not working at all :/ On google I found just a few snippets, but nothing different from my code. Does not really nobody change status from the ribbon via javascript??

Thank you

Share Improve this question asked Oct 21, 2011 at 14:26 o..oo..o 1,9317 gold badges36 silver badges65 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 1

For changing state of an entity you need to use the EntityMoniker, in in plugins and also in JScript.

Try the code from the following link:

Set Status or State of a Record Using Jscript

I was surfing on the web, because a friend of mine had the same problem, I haven't changed de statecode in CRM 2011 via JScript, but I think I have your solution.

In case of my friend, he had statecode value in wrong format, he was using 0 or 1, and service was returning an error telling him, 0 or 1 weren't correct values of statecode, then I though, coding in C# you have to put in State a value from an Enumeration ('Active' or 'Inactive'), he changed his integer value to 'Active' and the soap call runs fine.

Report the real solution if you arrive to it :)

See you.

本文标签: soapCRM 2011change statecodestatuscode by javascriptStack Overflow