Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  Getting error in creating a JSON using dynamic values in Architect

    Posted 13 hours ago

    I want to create a array of JSON objects with dynamic values. For that I am using a loop and inside each iteration I am trying to create the JSON object with property name and adding the created JSON object in a JSON Collection variable. 

    My expression - 

    If(!IsNotSetOrEmpty(Slot.Value),
    JsonParse("{\n  \"id\": ToInt(Task.TextID),\n  
                                 \"value\": \"Slot.Value\" \n}"),
    JsonParse("{\n  \"id\": ToInt(Task.TextID),\n 
    \"value\": \"\" \n}"))
    This is Throwing an error- Error.Expression.Value.NotAllowed. How can I resolve? 
    Also, Can I stores the array of JSON objects in JSON Collection variable??If not please suggest the way too. Actually I need to send an array of JSON objects as an input in an API. Is it possible?

    #Architect
    #DataActions

    ------------------------------
    Subhajit Podder
    NA
    ------------------------------


  • 2.  RE: Getting error in creating a JSON using dynamic values in Architect

    Posted 4 hours ago

    Hey Subhajit, how are you?

    Just looking at it it's kinda hard to figure out what you are trying to achieve.

    But I'm guessing you are trying to add a JSON Object that would look like this:

    {
    id: 9999999
    value: "xxxxx"
    }

    Is that correct?

    And on the variable "TextID" you have the numerical ID(like the 99999 on my example), but as a string, right?
    As for the Slot.Value variable, you have a text (like the "xxxxx" I mentioned above). Is all of the above correct?

    Try this:

    If(!IsNotSetOrEmpty(Slot.Value),
    JsonParse("{\n  \"id\": " + Task.TextID + ",\n  \"value\": \"" + Slot.Value + "\" \n}"),
    JsonParse("{\n  \"id\": " + Task.TextID + ",\n  \"value\": \"\" \n}"))

    What seems to be wrong on your current function is that you are trying to access the value of those variables inside the string that you are creating, so the value of the variables are not being accessed correctly (I believe). And also I see no reason for you to use the "ToInt" function on the ID, as you are creating a string that will then be parsed as a JSON (As long as the ID doesn't have any double quotes outside of it, it should be treated as a number, I believe).

    Well, try the above, let me know if it helps



    ------------------------------
    Marcello Jabur
    ------------------------------