Share via


Incrementing a Variable within LogicApp (Dynamics Source and Target)

Question

Tuesday, April 4, 2017 5:23 PM

Hi Guys,

Hoping someone can help!
I've produced a LogicApp using the Dynamics 365 Connectors as Source and Target.

It's a simple LogicApp, it retrieves a set of data from Dynamics, applies a $order criteria and then iterates over that set in a For Loop.

I've initialised a 'Count' variable outside of the For Each Loop and increment it within the loop. This value is then applied as a 'Rank' to the record I am updating.

From what I can see, my $orderby clause is working on the data set but my variable isn't incrementing in +1 as I thought it would. (See below).

Is there some weird parallelism going on here or have I totally missed something? - How can I get a simple count in the loop?

LOOP VALUE
1, 1
2, 3
3, 6
4, 4
5, 9
6, 2
7, 11
8, 12
9, 7
10, 8
11, 10
12, 5

Cheers!

All replies (3)

Tuesday, April 4, 2017 6:23 PM âś…Answered | 1 vote

Hi ojward,

By Default ForEach works in Parallel Execution. I think that's the reason may be you are not seeing variable Increment correctly.

Switch to code view and add Operation Options:Sequential Like Below.

 "foreach": "@body('email_filter')",
        "operationOptions": "Sequential"

This can Increment you the variable correctly in ForEach Loop.

Below Article can give you a better idea on Variables usage in Logic Apps.

http://www.bizbert.com/bizbert/2017/03/25/AddingVariablesToLogicApps.aspx

Thanks,

Sujith.

Sujith


Wednesday, April 5, 2017 4:42 AM

Hi Ojward86,

Variables were made available in the logic apps very recently (24th March 2017 you can check the hangout session on  link  https://www.youtube.com/watch?v=_XioR4M6moQ )by Microsoft and have some limited support. some limitations are

1) Variable have to global

2) Only Integer and Float are supported

3) Only initialization and incrementation is supported.

AS sujith has pointed out refer the article 

Adding Variables to Logic apps

Regards,

Mandar Dharmadhikari


Wednesday, April 5, 2017 9:26 AM

Brilliant! Thanks Sujith.

I figured that it must be exectuing in Parallel but I couldn't find a way to force it to run sequentially.
Works perfectly. - Thanks for the resource.

Cheers.