08-23-2023 05:21 AM
I have been creating an integration between salesforce and another system. The issue comes up when there are multiple Location Objects involved from Salesforce. How can we have dynamic Keys generated. See the snippet below to get a better idea:
{
"destinations":{
"0":"dest1",
"1":"dest2"
}
}
How would we be dealing with the dynamic number of destinations with this payload design?
Solved! Go to Solution.
08-23-2023 09:07 AM - edited 08-23-2023 09:07 AM
There are different ways to handle this, but I think the simplest is to take the object into a Ruby or JS action and reformat it into something consistent and parsable.
Using your data above, this will work in a Ruby action:
dest = input["destinations"]
keys = dest.keys
reformat = []
keys.each { | k |
obj = {}
obj["key"] = k
obj["value"] = dest[k]
reformat.push(obj)
}
{reformat: reformat}
Output:
[
{"key":"0", "value":"dest1"},
{"key":"1", "value":"dest2"}
]
08-23-2023 09:07 AM - edited 08-23-2023 09:07 AM
There are different ways to handle this, but I think the simplest is to take the object into a Ruby or JS action and reformat it into something consistent and parsable.
Using your data above, this will work in a Ruby action:
dest = input["destinations"]
keys = dest.keys
reformat = []
keys.each { | k |
obj = {}
obj["key"] = k
obj["value"] = dest[k]
reformat.push(obj)
}
{reformat: reformat}
Output:
[
{"key":"0", "value":"dest1"},
{"key":"1", "value":"dest2"}
]