带有“if”的错误使用“substring”时的函数 [英] Bug with "if" function when using "substring"

查看:106
本文介绍了带有“if”的错误使用“substring”时的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试处理Zipcode时,我在Logic Apps中遇到了一种奇怪的行为。

I experienced a very odd behavior in Logic Apps today when trying to process a Zipcode.

所需的行为是对zipcode的前5个字符进行子串。

The desired behavior was to substring the zipcode's first 5 characters.

我希望以下表达式能够正常工作,但是当邮政编码长度为5个或更少字符时,它会一直抛出错误:

I expected the following expression to work, but it kept throwing errors when the zipcode length was 5 or less characters:

if(greaterOrEquals(length( triggerBody()?['zip']),6),string(substring(triggerBody()?['zip'],0,5)),triggerBody()?['zip'])

当它以< = 5个字符运行时会出现以下错误:例如59771或5977

'模板语言函数'substring'参数超出范围:'start index'和'length'必须是非负整数,并且它们的总和不得大于字符串的长度。

I would get the following error when it ran with <=5 characters: such as 59771 or 5977
'The template language function 'substring' parameters are out of range: 'start index' and 'length' must be non-negative integers and their sum must be no larger than the length of the string.

根据我对条件及其预期行为的所有期望,不应发生此错误。执行引擎应该跳过THEN操作,并且不应该对子字符串函数进行评估。 

By all my expectations of conditionals and their expected behavior, this error should not have occurred. The execution engine should have skipped the THEN operation and the substring function should NEVER have been evaluated. 

我通过替换"substring"进行了一些额外的测试。在THEN操作中调用返回一个简单的字符串值并按预期​​返回ELSE操作的结果并且没有抛出任何错误。

I did some additional testing by replacing the "substring" call in the THEN operation with a simple string value returned and as expected the result of the ELSE operation was returned and no error was thrown.

然后我试图反转我的逻辑并且一切都开始工作:

if(lessOrEquals(length(triggerBody()?['zip']),5),triggerBody()?['zip'],substring(triggerBody()?['zip '],0,5))

I then tried reversing my logic and everything started working:
if(lessOrEquals(length(triggerBody()?['zip']),5), triggerBody()?['zip'], substring(triggerBody()?['zip'],0,5))

这让我觉得在IF操作中,THEN语句由工作流引擎评估,而不管条件操作的结果如何;虽然幸运的是没有评估ELSE声明。

This makes me think that in the IF operation, the THEN statement is evaluated by the workflow engine regardless of the result of the conditional operation; although the ELSE statement is fortunately not evaluated.

对于像我的zipcode规范化这样的用例,这是非常有问题的,因为IF的重点是避免执行一些无效的代码。

For a usecase like my zipcode normalizing, that is extremely problematic as the whole point of the IF was to avoid executing some code that would be invalid.

这是一种已知行为吗?还有其他人看过吗?

Is this a known behavior? Has anyone else seen this?

推荐答案

<嘿嘿伙伴, 

Hey Mate, 

我尝试了你的表达'bigorequals ...'并且正如预期的那样行为。 我总体上理解的方式并参考了这个  链接
,是整个事物可以被称为函数表达式,它被内部评估。这意味着表达式

substring(triggerBody()?['zip'],0,5)
在'if(。)之外的条件之前进行评估。 ..)',因此如果邮政编码的长度小于等于5,则会收到错误。

I tried your expression 'greaterorequals...' and as expected the same behavior.  The way I understand overall and referring this link , is that the whole thing can be called a functions expression, which gets evaluated inside out. which means that the expression substring(triggerBody()?['zip'],0,5) gets evaluated before the condition outside 'if (...)', hence you get the error in case the the length of the zipcode is less than equal to 5. 

我不会真的称这是一个错误,但是关于工作流定义语言的事实:)。干杯。

I won't really call this is a bug but a fact about workflow definition language :). Cheers.


这篇关于带有“if”的错误使用“substring”时的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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