Skip to main content

Hi All. I was hoping someone can help me understand what I am missing here in terms of how the For Each works in Studio. I have attached a document to help visualize and tell my story. I am pulling the records in using the table_id field as my index/reference and only wanting to process the PENDING status records. For each record it then calls the same table list passing in the table_id to return all the other field values, calls the AD smart object to create the Active Directory records with the fields, then sets the STATUS to COMPLETED. It only runs though for the first record. If I remove the filter/input mapping of PENDING it will process all the records as I would expect it too. What am I missing here? Thanks, Steve

Hi Steven_Rossi,

 

I'm not sure what could be the issue with for each loop at your end as it seems that every thing is properly set, but i can suggest you, Insted of For Each Loop, Try using traditional method Plan Per Slot No Destinations to loop through the items, as it is much quicker.

 

Check the below link where it will show how to set the Destination Rule and get the Id from the ActivityInstanceDestination Instance Data.

https://vijaydk2guy.wordpress.com/2017/03/25/workflow-for-loop-vs-destination-rule-plan-per-slot-no-destinations/

 

Regards,

VJay.


Thanks a lot for helping me out VJay. I attached another document showing trying to use the destination rule. I get an error though when trying to map the InstanceData back into my next smart object, telling me: "Ensure that the value corresponds to data type". Not sure what I am missing there. Also, how does it know to loop through the records? Steve

Hi Steve,

 

Try Using Conversion Function, Convert to Number from Context Browser, as activityInstanceDestination Data by default considered as string and you are using it to assign it a number field.

 

From ContextBrowser-->Function Browser  (fx)-->Select ToInteger(Value)-->NAvigate to Workflow Context Browser -- > Select  Activity Destination Instance--> Select Instance Data.--> Now asssign this to your SMO input field.

 

 

Try this and let me know if it works Steve..

 

Vijay.

 

 

 


Hi VJay. That worked like a charm, thanks. however, now I am not sure how its behaving. I included a snapshot to show. Its as if it is skipping over the first record and then creates the AD record successfully for the second record, but does not update the record to COMPLETED. It also error's in the workflow suggesting it is trying to create the same AD user account again. So I must be missing something from your prior web post but still not certain as I understand the behavior of how this is working/looping. Thanks for your help! Steve

Hi Steve,

 

Can you just try below steps.

 

While setting the SmartObject in Destination Rule, Select Order Results by Checkbox and select the ID Field that you are using inside the activty.

 

 

See if it works!!

 

Vijay.


Hi VJay. Sorry to keep being a pest on this. Its still behaving the same way (new snapshot). It seems I am still missing something critical in terms of how its looping through the records. It creates the AD record for the second row and then errors trying to make the same AD record and then never issues the update statement to complete. Also included the package in case its easiar to load and view what I am doing.

 

 

Steve


Its ok steve, it happens sometime :-)

 

K2proj that you have attached doesn't open, i think its missing the Process file, No issues , i would try to setup same scenario in my environment and see whether i could able to replicate your issue.

 

Mean while i would suggest you to try couple of things.

 

Check the status Column, Database values has any leading or trailing spaces.

 

Try Setting the Order Results by to Descending.

 

 

1.  Remove all events in for loop activity, and add event to log the items to some db to see exactly what are the items that are being looped. Try both cases, with filter and with out filter.

 

2. Add more rows in data base and do the step 1 to see what exactly are the items  that are being looped.

 

Also could you let me know the K2 version that you are working on

 

Regards,

Vijay.

 

 


Hi VJay. I will try those suggestions out and let you know. I sent you the wrong project file. I attached the two files again for you.

Hi VJay. My tests are only showing one record being seen regardless of how I sort it. I am missing something from your web post. If you could post me an example process you have working on your end that you can post for me I would greatly appreciate it. I would certainly prefer to use your suggested method.

 

However, I did identify what I was doing wrong in my For Each loop or at least what I needed to do to get it working properly. Use the following URL to help:

 

https://simonatk2.wordpress.com/2016/10/19/how-to-for-each-event/

 

Instead of adding a filter to only pull PENDING records directly on the For Each (which intuitively I would think should work), I created a Reference to the record so I could work with only the Pending records but then I was missing the Line for records that were not in PENDING status.

 

 


Hi Steve,

 

 

I tried Replicating your issue but couldn't able to do, as i can get it run in both for loop as well as dynamic destination rule.

Let'd do one thing, if you are ok to have a GoTo Session, let's have it some time today.

 

you can ping me on linkedin https://www.linkedin.com/in/vijayrangisetty/ when you are ready.

 

Regards,

VJay.


Thanks ViJay for all your help. Just to inform anyone else reading this post, I ended up having to go with using the For Each (as described previously) for what I needed to do, because if you need to have conditional logic off of an activity you need to use the For Each. The Plan Per Slot No Destinations method as Vijay provided how to do, allows you to loop through the records within the one activity. So for example to loop through records using this method and not a For Each to create AD records looks something like the attached document.

 

Steve 


Reply