JavaScript在Form Onchage中触发两次

问题描述 投票:0回答:1

我想更改状态时使用Javascript触发流程。一切正常,但是当我更改记录状态时,JavaScript函数触发了两次。

我认为问题在于节省。enter image description hereenter image description hereenter image description hereenter image description here

storno=function (executionContext)
{
	var functionName = "storno";
	var formContext = executionContext.getFormContext();
	if(formContext.getAttribute("statecode").getValue() == 3)
	{ 
		//try{
			var data= {"id": ""};
			data.id = formContext.data.entity.getId();
			var requestUrl = "https://prod-78.westeurope.logic.azure.com:443/workflows/6bff2c7051424e00b8519160db83c1bf/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=sfSBGx1gP3WzU1x7XMY64WVFc_RJ6EBMadIBnNudKR4";
			var req = new XMLHttpRequest();
			req.open("POST",requestUrl,true);
			req.setRequestHeader("Accept","application/json");
			req.setRequestHeader("Content-Type","application/json; charset=utf-8");
			req.setRequestHeader("OData-MaxVersion","4.0");
			req.setRequestHeader("OData-Version","4.0");
			req.onreadystatechange = function(){
				if(this.readyState == 4 || this.readyState == 2){
					req.onreadystatechange = null;
				
					if (this.status == 200 || this.status == 204 || this.status == 202){
						formContext.data.refresh(true);
		       Xrm.Utility.openEntityForm(formContext.data.entity.getEntityName(),formContext.getAttribute("description").getValue());
						
					}
					//else{
					//	var error = JSON.parse(this.response).error;
					//}
				}
			};
			req.send(JSON.stringify(data));	
		//}
		//catch(ex){
		//Obj_RunFlow.throwError(functionName,ex.massage);
		//}
	}
		
};
javascript dynamics-crm microsoft-dynamics dynamics-crm-webapi
1个回答
0
投票

我可以加2美分。

为什么要通过Javascript触发流,而现在通过CDS连接器触发流。

[如果您使用Javascript触发流程,则只有在用户与按钮进行交互时才会触发。如果通过某些后台逻辑或其他插件更改了Record(状态),您的流程将不会触发。

要使您的流程在所有情况下都通过状态更改运行,请通过后台逻辑的用户交互来进行,

我更希望通过CDS连接器运行流程,也希望通过when Record is updated运行流程,并过滤掉您的字段,使其仅是状态。

这样,只有在更改状态字段时,流才会自动触发。

© www.soinside.com 2019 - 2024. All rights reserved.