Author Message
Andrew.Prokop
Joined: Oct 28, 2014
Messages: 179
Offline
I am trying to create a variable for this JSON:

{"result":[{"u_active_2":"true","u_phone_1":"2305"}]}

I built:

{"title":"aivalues","type":"object","properties":{"result":{"type":"array","items":{"type":"object","properties":{"u_phone_1":{"type":"string"},"u_active_2":{"type":"boolean"}}}}}}

But I get a run-time exception when I try to access u_active_2 like this:

aivalues["result"][0]["u_active_2"]

I am told that String is incompatible with Boolean.

I tried a n number of other gyrations, but nothing works. Can someone help me understand what the right variable expression should be? Thanks!
AnuragAggarwal
Joined: Jun 1, 2014
Messages: 154
Offline
if you want to use booleans then u_active_2:true is the correct way, putting quotes around true makes it a string
Andrew.Prokop
Joined: Oct 28, 2014
Messages: 179
Offline
I have tried aivalues["result"][0][u_active_2]:true and aivalues["result"][0][u_active_2:true]. Both tell me "Unexpected token : "
AnuragAggarwal
Joined: Jun 1, 2014
Messages: 154
Offline
no, i meant change data

from
{"result":[{"u_active_2":"true","u_phone_1":"2305"}]}

to

{"result":[{"u_active_2":true,"u_phone_1":"2305"}]}



or you can keep data as is and change expression to

aivalues["result"][0][u_active_2] == "true"
PrakashN
Joined: Jun 30, 2015
Messages: 105
Offline
Andrew,

Where and how exactly are you trying to use the "aivalues" object? I just now tried to create a simple workflow, created a user-defined Start Schema that matches your object, and used it in a Log Message task to assign to a string. It works fine. Just two points:

(1) aivalues["result"][0]["u_active_2"].toString() - This will make it a string, like "true" or "false".

(2) aivalues["result"][0]["u_active_2"] - Assigned straight to a boolean variable and it works just like that without any transformations.

I have the workflow available for you if you like (attached). Please note - this is just a simple workflow that does nothing but demonstrate these two assignments.

If you can describe more on how exactly you are receiving the data and how you are trying to use it, then we debug it more with a more clear demonstration workflow. Maybe, your JSON data has "true" or "false" enclosed in quotes, so it is actually a string, but you are trying to force that into a boolean variable? Just thinking...

Please let us know more after looking at the attached workflow. Thanks!
Filename BooleanAssignSample.xml [Disk] Download

Prakash Natarajan System Architecture Consulting Engineer Engagement Designer Avaya
Andrew.Prokop
Joined: Oct 28, 2014
Messages: 179
Offline
Yes, the JSON from ServiceNow has true in quotes (I included the received JSON in my first post). I failed to see that.

Thanks for the help.
Go to:   
Mobile view