Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.
SRP_JSON guidance
Hello all (and Happy New Year)
I obviously partook a tad too much over the festive season as now I am having a brain fade.
I have a comma-seperated array of values that I am trying to set using SRP_JSON (SETVALUE). Techincally it is a string but I need to pass it to the 3rd Party as not one ...
I used this:
SRP_JSON(ROOTHANDLE, "SETVALUE", "JobId", "[":ListUnDelivered:"]")
I need to have this:
{"JobId":[6130,6138,6149,6170,6134,6152,6155,6143,6161,6164,6137,6158,6167,6140]}
I actually get:
{"JobId":"[6130,6138,6149,6170,6134,6152,6155,6143,6161,6164,6137,6158,6167,6140]"}
Unfortunately the 3rd party then treats the above as a single job and hence fails on multiple levels.
Maybe I am using the wrong Service? How can I add to JSON without the quotes identifying it as a string?
I know I can workaround this a couple of ways but Id rather use SRP_JSON right ....
I obviously partook a tad too much over the festive season as now I am having a brain fade.
I have a comma-seperated array of values that I am trying to set using SRP_JSON (SETVALUE). Techincally it is a string but I need to pass it to the 3rd Party as not one ...
I used this:
SRP_JSON(ROOTHANDLE, "SETVALUE", "JobId", "[":ListUnDelivered:"]")
I need to have this:
{"JobId":[6130,6138,6149,6170,6134,6152,6155,6143,6161,6164,6137,6158,6167,6140]}
I actually get:
{"JobId":"[6130,6138,6149,6170,6134,6152,6155,6143,6161,6164,6137,6158,6167,6140]"}
Unfortunately the 3rd party then treats the above as a single job and hence fails on multiple levels.
Maybe I am using the wrong Service? How can I add to JSON without the quotes identifying it as a string?
I know I can workaround this a couple of ways but Id rather use SRP_JSON right ....
Comments
There are various ways of approaching this, but I think the most efficient way is to first create an array object using the NEW service:
SRP_JSON(arrayUndelivered, 'New', 'Array', LIstUndelivered, ',')
Then SET this as the value to your JobId property:
SRP_JSON(ROOTHANDLE, 'Set', 'JobId', arrayUndelivered)
Of course, RELEASE your array since you no longer need it:
SRP_JSON(arrayUndelivered, 'Release')
P.S. This is untested code and I am not near a copy of OI to even verify the syntax.
I haven't tried it yet myself but basically it would be something like this
Result = SRP_Json(jobHandle, "New", "ARRAY")
SRP_Json(jobHandle, "AddValueArray", ListUnDelivered, ",")
SRP_JSON(ROOTHANDLE, "SET", "JobId", jobHandle)
Untested but I think that's the gist
I think that just proves I need to read release notes a little more thoroughly (or more to the point, remember them after I read them!)
Cheers!
I tried a couple of tweaks but didn't find a way that it worked as expected or at least as I expected but maybe I've misunderstood its intent?
Perhaps @kevinfournier can shed some light on it?
Here's an example of what's being referred to
Create an array using "NEW" but no initialisation.
Use AddValueArray to populate it
End up with an array within an array.
"site_address": [
[
"Level 3",
"21 Smith St"
]
],
when what was expected was
"site_address": [
"Level 3",
"21 Smith St"
],
[ "Level 3", "21 Smith St" ]
Then it is parsed (using the delimiter you passed in, which was a comma), then AddValueArray breaks it into two elements...
[ "Level 3"
...and...
"21 Smith St" ]
...and adds those two elements into a JSON array. That's why you get the double brackets. Again, this is for passing standard OI arrays like this:
Array = "Level 3":@VM:"21 Smith St" SRP_Json(Handle, "AddValueArray", Array, @VM)
Rule of thumb: if you have JSON, the only real thing you can do with it is Parse.
If SRP_Json(custHandleX, "New", "Array") then address = "Level 3":vm$:"21 Smith St" Result = SRP_Json(custHandleX, "AddValueArray", address, @VM) SRP_Json(custHandle, "Set", "site_address", custHandleX) SRP_Json(custHandleX, "RELEASE") end
Results in
"customer": { "site_address": [ [ "Level 3", "21 Smith St" ] ], }
address = "Level 3":vm$:"21 Smith St" SRP_Json(custHandle, "SetValueArray", "site_address", address, @VM)
AddValueArray and SetValueArray are parallel to AddValue and SetValue. They add or set values without having to do a New..Release.