【发布时间】:2013-09-28 18:30:40
【问题描述】:
我已经查看了论坛,但似乎无法获得我需要工作的内容。
在潜在客户实体上,当用户创建新潜在客户时,工作流会在之前运行以更改某些潜在客户字段。
我发现这只能通过 javascript 和实体设置中的 onload 实现。
我已经创建了工作流和一个 JavaScript 文件,并将其设置为在加载时运行。我使用的 Javascript 是:
function callworkfow(workflowId, entityId) {
var request =
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<request i:type="b:ExecuteWorkflowRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011 /Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
<a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<a:KeyValuePairOfstringanyType>
<c:key>B3D77337-D5FD-E211-BB05-005056AF0003</c:key>
<c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">EntityIdValue</c:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<c:key>2EF8C158-182B-444A-A9DF-FF2DC5E44514</c:key>
<c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization /">WorkflowIdValue</c:value>
</a:KeyValuePairOfstringanyType>
</a:Parameters>
<a:RequestId i:nil="true" />
<a:RequestName>ExecuteWorkflow</a:RequestName>
</request>
</Execute>
</s:Body>
</s:Envelope>
var xhr = new XMLHttpRequest();
xhr.open('POST', '/XRMServices/2011/Organization.svc/web', true);
xhr.setRequestHeader('Accept', 'application/xml, text/xml, */*');
xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xhr.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute');
xhr.onreadystatechange = function () { alert(xhr.status); };
xhr.send(request);
}
但是加载失败。
如果有人可以帮助我,我将不胜感激。只需要 JavaScript 即可简单地加载工作流。哦,而且具有跨平台兼容性。
function SetLookupValue(fieldName, id, name, entityType) {
if (fieldName != null) {
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = id;
lookupValue[0].name = name;
lookupValue[0].entityType = entityType;
Xrm.Page.getAttribute(fieldName).setValue(lookupValue);
}
}
var ExistingCase = curentUserId = Xrm.Page.context.getUserId();
if (ExistingCase.getValue() != null) {
var ExistingCaseGUID = ExistingCase.getValue()[0].id;
var ExistingCaseName = ExistingCase.getValue()[0].name;
SetLookupValue("new_accountmanager", ExistingCaseGUID, ExistingCaseName, "incident");
}
【问题讨论】:
-
您添加到 CRM 表单的文件中是否还有其他脚本?看起来您正试图以不受支持的方式访问表单元素。例如使用 DOM 代替 XRM 对象。
-
没有。这一切都非常标准。在创建潜在客户时,我需要有一个工作流更改字段。显然,以标准方式使用工作流,您只能在打开潜在客户后执行。
-
您的工作流程更新了哪些字段、实体?
-
目前只是一个自定义字段,用于将字段从一个选项更改为另一个选项。看看脚本是否有效的简单方法。
-
您想更改刚刚打开的潜在客户表单上的字段吗?
标签: javascript workflow dynamics-crm-2011 microsoft-dynamics