无法通过 JavaScript 更改创建的自定义状态原因
Cannot change created custom Status Reason via JavaScript
我已经更改了 salesorder
实体并在 Submitted
中创建了一个新的 status reason
。
我在 submitted
状态下添加了一个名为 PreTransport
的 status reason
,其值为 100000004
。
我可以通过这个请求从 Active
state
(pending status reason
) 到 Submitted
state
(In-Progress
status reason
) :
var request = ""
request += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
request += " <s:Body>";
request += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
request += " <request i:type=\"b:SetStateRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
request += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
request += " <a:KeyValuePairOfstringanyType>";
request += " <c:key>EntityMoniker</c:key>";
request += " <c:value i:type=\"a:EntityReference\">";
request += " <a:Id>" +recordGuid+ "</a:Id>";
request += " <a:LogicalName>salesorder</a:LogicalName>";
request += " <a:Name i:nil=\"true\" />";
request += " </c:value>";
request += " </a:KeyValuePairOfstringanyType>";
request += " <a:KeyValuePairOfstringanyType>";
request += " <c:key>State</c:key>";
request += " <c:value i:type=\"a:OptionSetValue\">";
request += " <a:Value>"+stateCode+"</a:Value>";
request += " </c:value>";
request += " </a:KeyValuePairOfstringanyType>";
request += " <a:KeyValuePairOfstringanyType>";
request += " <c:key>Status</c:key>";
request += " <c:value i:type=\"a:OptionSetValue\">";
request += " <a:Value>"+statusCode+"</a:Value>";
request += " </c:value>";
request += " </a:KeyValuePairOfstringanyType>";
request += " </a:Parameters>";
request += " <a:RequestId i:nil=\"true\" />";
request += " <a:RequestName>SetState</a:RequestName>";
request += " </request>";
request += " </Execute>";
request += " </s:Body>";
request += "</s:Envelope>";
//send set state request
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", true)
// Responses will return XML. It isn't possible to return JSON.
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");
var successCallback = null;
var errorCallback = null;
req.send(request );
但是在同一个state
中的In-Progress
到PreTransport
之间不起作用。
我想这是因为 permission
。我应该为这个新 status reason
设置权限吗?
如果是,我该怎么做?
请注意,我在内部部署了 CRM 2011。
注意:我也试过这段代码,但没有成功。
XrmServiceToolkit.Soap.SetState("salesorder", Xrm.Page.data.entity.getId(), 1, 100000004,false);
抱歉,我无法访问 2011 版。但我在 CRM Rest builder 中测试了下面的代码片段,它工作得很好。
我在 1 : Submitted
的 status (StateCode)
下创建了一个价值 100000000 : Shipping ready
的自定义 status reason (StatusCode)
。确保您正在经历允许的转换,例如 answered here.
var entity = {};
entity.StateCode = {
Value: 1
};
entity.StatusCode = {
Value: 100000000
};
XrmServiceToolkit.Rest.Update("B4B625A1-3789-E811-A967-000D3A1A9407", entity, "SalesOrderSet", function() {
//Success - No Return Data - Do Something
}, function(error) {
Xrm.Utility.alertDialog(error.message);
}, true);
我已经更改了 salesorder
实体并在 Submitted
中创建了一个新的 status reason
。
我在 submitted
状态下添加了一个名为 PreTransport
的 status reason
,其值为 100000004
。
我可以通过这个请求从 Active
state
(pending status reason
) 到 Submitted
state
(In-Progress
status reason
) :
var request = ""
request += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
request += " <s:Body>";
request += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
request += " <request i:type=\"b:SetStateRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
request += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
request += " <a:KeyValuePairOfstringanyType>";
request += " <c:key>EntityMoniker</c:key>";
request += " <c:value i:type=\"a:EntityReference\">";
request += " <a:Id>" +recordGuid+ "</a:Id>";
request += " <a:LogicalName>salesorder</a:LogicalName>";
request += " <a:Name i:nil=\"true\" />";
request += " </c:value>";
request += " </a:KeyValuePairOfstringanyType>";
request += " <a:KeyValuePairOfstringanyType>";
request += " <c:key>State</c:key>";
request += " <c:value i:type=\"a:OptionSetValue\">";
request += " <a:Value>"+stateCode+"</a:Value>";
request += " </c:value>";
request += " </a:KeyValuePairOfstringanyType>";
request += " <a:KeyValuePairOfstringanyType>";
request += " <c:key>Status</c:key>";
request += " <c:value i:type=\"a:OptionSetValue\">";
request += " <a:Value>"+statusCode+"</a:Value>";
request += " </c:value>";
request += " </a:KeyValuePairOfstringanyType>";
request += " </a:Parameters>";
request += " <a:RequestId i:nil=\"true\" />";
request += " <a:RequestName>SetState</a:RequestName>";
request += " </request>";
request += " </Execute>";
request += " </s:Body>";
request += "</s:Envelope>";
//send set state request
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", true)
// Responses will return XML. It isn't possible to return JSON.
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");
var successCallback = null;
var errorCallback = null;
req.send(request );
但是在同一个state
中的In-Progress
到PreTransport
之间不起作用。
我想这是因为 permission
。我应该为这个新 status reason
设置权限吗?
如果是,我该怎么做? 请注意,我在内部部署了 CRM 2011。
注意:我也试过这段代码,但没有成功。
XrmServiceToolkit.Soap.SetState("salesorder", Xrm.Page.data.entity.getId(), 1, 100000004,false);
抱歉,我无法访问 2011 版。但我在 CRM Rest builder 中测试了下面的代码片段,它工作得很好。
我在 1 : Submitted
的 status (StateCode)
下创建了一个价值 100000000 : Shipping ready
的自定义 status reason (StatusCode)
。确保您正在经历允许的转换,例如 answered here.
var entity = {};
entity.StateCode = {
Value: 1
};
entity.StatusCode = {
Value: 100000000
};
XrmServiceToolkit.Rest.Update("B4B625A1-3789-E811-A967-000D3A1A9407", entity, "SalesOrderSet", function() {
//Success - No Return Data - Do Something
}, function(error) {
Xrm.Utility.alertDialog(error.message);
}, true);