CRM2011通过ribbon按钮启动工作流

在实施的项目中,有时候客户可能会觉得点击系统的工作流按钮显得有些繁琐,

因为在点击运行完之后,系统还会弹出一个对话窗口,让你确认是否继续:



沟通之后,发现他们想要的不是这种有意识的点击“Next”,而是友好的提醒你:“流程开始运行了”之类的话。

现在我们可以通过在表单窗体的Ribbon上添加一个按钮,然后将Ribbon的Action链接到一个JS文件,并指定函数名,在JS文件中实现

启动工作流的操作。

一.为了简化操作,用Visual Ribbon Editor for CRM2011来实现添加按钮,下面为”客户“窗体添加一个”StartWorkflow“按钮:



切换到Action选项卡,如图:



编辑完成之后,点击”Save“按钮,即可导入CRM中,在CRM2011的客户窗体中,显示如下:


前面配置的时候命名是”StartWorkflow“,由于工具默认使用的语言是1033,但系统使用的是2052,所以在这里被显示成”自定义“。

二.新建一条工作流,并记下工作流guid,工作流设置成"作为按需流程",最后激活流程


三.创建new_workflow.js文件,并发布


点击“文本编辑器”,录入如下内容:

ExecuteWorkflow = function(entityId, workflowId){
 

// Soap Request for Executing Workflow
                                        var executeWorkflowSoapRequest = "" +
                    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                    "<soap:Envelope xmlns:soap=\'http://schemas.xmlsoap.org/soap/envelope/\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\'>" +
                    GenerateAuthenticationHeader() +
                    "  <soap:Body>" +
                    "    <Execute xmlns=\'http://schemas.microsoft.com/crm/2007/WebServices\'>" +
                    "      <Request xsi:type=\"ExecuteWorkflowRequest\">" +
                    "        <EntityId>" + entityId + "</EntityId>" +
                    "        <WorkflowId>" + workflowId + "</WorkflowId>" +
                    "      </Request>" +
                    "    </Execute>" +
                    "  </soap:Body>" +
                    "</soap:Envelope>" +
                    "";
 
// using ajax for the request
                    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
                    xmlHttpRequest.setRequestHeader("SOAPAction",'http://schemas.microsoft.com/crm/2007/WebServices/Execute');
                    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                    xmlHttpRequest.setRequestHeader("Content-Length", executeWorkflowSoapRequest.length);
                    xmlHttpRequest.send(executeWorkflowSoapRequest);
 
// response of the workflow request
                    var resultXml = xmlHttpRequest.responseXML;
}
 
function OnClickRibbon()
{
// Get the guid of the workflow created. This can be retrieved from the url of the workflow
// page.
var workflowProcessID = '423f415e-6612-492b-a186-306a4ace3b4d';
 
// Get entity Name
var entityName = Xrm.Page.data.entity.getEntityName();
 
// Get Type Code for entity
var entityID = Xrm.Page.data.entity.getId();

// stores the response whether workflow has executed or any error.
var executeWorkflowResponse = '';
 
executeWorkflowResponse = ExecuteWorkflow(entityID, workflowProcessID);

alert("流程开始运行了,亲!");

}
上面蓝色字体部分替换成前面记录的流程GUID即可。

四.刷新某一“客户”记录窗体,并点击之前创建的Ribbon按钮,显示如下:






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值