Legacy Dev Forum Posts

 View Only

Sign Up

Insert loop in custom action

  • 1.  Insert loop in custom action

    Posted 06-05-2025 18:40

    SergioRota | 2018-03-12 08:19:57 UTC | #1

    Hi,

    Can I insert a Loop (ex. for - loops through a block of code a number of times) in a custom action?

    Thanks Sergio


    Jason_Mathison | 2018-03-12 12:49:25 UTC | #2

    Can you be specific about what you are trying to do? The templates have a little flexibility to loop.


    SergioRota | 2018-03-12 13:28:13 UTC | #3

    I would execute a loop to retrieve multiple records.

    Is there a method to store the result from array to object?


    Jason_Mathison | 2018-03-12 13:42:40 UTC | #4

    If you are asking if an action can make multiple calls out to a web service, the answer is no.

    Is there a method to store the result from array to object?

    You can setup your output contract to return an array of strings. Make sure to verify that everything works in test mode with flattening enabled. Once you have that working you should be able to access the array of strings in architect or scripts.

    A few other notes, if you only want the first result in the array, use successTemplateUtils.firstFromArray https://help.mypurecloud.com/articles/velocity-macros-data-actions/

    If you are unsure how to create the output schema you could try putting the response from mscrm into a tool like https://jsonschema.net/ and let it create a schema that you could then edit down to what you want.


    SergioRota | 2018-03-12 14:10:05 UTC | #5

    Jason_Mathison, post:4, topic:2595
    You can setup your output contract to return an array of strings. Make sure to verify that everything works in test mode with flattening enabled. Once you have that working you should be able to access the array of strings in architect or scripts.

    I try in this method:

    The Test:

    In Architect:


    Jason_Mathison | 2018-03-12 19:09:56 UTC | #6

    A couple of things: Making the value.accountid required would help point out if any value is being assigned to it, and if it is the right type. If a property it isn't marked as required then the schema doesn't really enforce correctness, it just indicates that the property might be there.

    In order to get the schema correct I recommend creating a schema with a tool like https://jsonschema.net/. That type of tool creates a schema based on example JSON, in this case the results you got from MS Dynamics. You will probably want to remove some of the schema, but it will quickly get you close.

    Finally, when possible, please paste in the text of configuration and output instead of an image of it. Cut and paste is much faster and more reliable than reentering the data.


    SergioRota | 2018-03-13 09:01:55 UTC | #7

    Jason_Mathison, post:6, topic:2595
    Making the value.accountid required would help point out if any value is being assigned to it

    Thanks :grinning: the action retrieve account ids and I can see these ids in script :muscle:t4:

    Jason_Mathison, post:6, topic:2595
    In order to get the schema correct I recommend creating a schema with a tool like https://jsonschema.net/. That type of tool creates a schema based on example JSON, in this case the results you got from MS Dynamics. You will probably want to remove some of the schema, but it will quickly get you close.

    I don't understand how insert my custom action in https://jsonschema.net/

    Now, a last question for you: I have these ids in a string, can i store a single id in a string?

    Thanks for your help


    Jason_Mathison | 2018-03-15 18:08:13 UTC | #8

    I don’t understand how insert my custom action in https://jsonschema.net/

    You can copy the response you get from MS Dynamics into that site and it will create a schema that matches it.

    Now, a last question for you: I have these ids in a string, can i store a single id in a string?

    I don't have any experience with the Scripts UI, so if you are having issues with it I would post in that applications room.


    system | 2018-04-15 18:08:15 UTC | #9

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 2595