JavaScript在Form Onchage中触发了两次 [英] JavaScript triggered twice in Form Onchage

查看:166
本文介绍了JavaScript在Form Onchage中触发了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use Javascript to trigger a Flow when I want to change the state. Everything worked fine but the JavaScript function triggered two times when I change the state my record.

我认为问题在于保存.

i think the Problem is something with the save.

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);
		//}
	}
		
};

推荐答案

我可以加2美分.

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

Why are you firing your flow via Javascript and now via CDS connector.

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

If you fire your flow with Javascript, it will trigger only when user interaction with button happens. Your flow will not trigger if Record (status) is changed by some background logic or some other plugin.

要让您的流程在所有情况下均基于状态更改运行,请通过后台逻辑的用户交互来进行操作,

To make your flow run on Status change under all circumstances let it be via user interaction of background logic,

我更希望通过CDS连接器运行流,并且在运行时记录已更新,并将您的字段过滤为仅状态.

I would prefer running your flow via CDS connector and that too when Record is updated and filter out your field to be only Status.

通过这种方式,只有在状态"字段发生更改时,您的流程才会自动触发.

In this way your flow will get triggered automatically only when Status field is changed.

这篇关于JavaScript在Form Onchage中触发了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆