I am using a!fromJson to convert a JSON string into an Appian value. However, I encounter an error when handling document types.
a!fromJson
This is the current format I am using:
in ER: """" & fv!item & """:[" & substitute(if(rule!GLB_isBlank(local!data[fv!item]), "", local!data[fv!item]),";",",") & "]",OUTPUT: "fieldName":[[Document:115497], [Document:115501]]
but It's giving error 'The json Text parameter was not valid JSON'
Discussion posts and replies are publicly visible
Try to wrap your local!data[item] into integer. This will give you just the numbers and it will become an integer array.
"""" & fv!item & """:[" & substitute( if( rule!GLB_isBlank(local!data[fv!item]), "", tointeger(local!data[fv!item]) ), ";", "," ) & "]"
getting this output "fieldName" :[∞]
Just a quick question. How are you getting this JSON? It looks like you are creating one by yourself. So why not directly use a!toJson on a map or dictionary?
I'm getting data from a CDT
That doesn't make sense. CDT doesn't have any data. It is the database that has it. And if you are getting data from DB, why do you need to involve JSON? Can you add the entire code snippet here?
a!localVariables( local!data: rule!xxxxxx( Id: 8 ).data[1], local!keys: dictutil_getkeys( local!data ), local!listOfDifferences: a!forEach( items: local!keys, expression: if(fv!item = "yyyyy", """" & fv!item & """:[" & substitute(if(rule!GLB_isBlank(local!data[fv!item]), "", tointeger(local!data[fv!item])),";",",") & "]", """" & fv!item & """:""" & local!data[fv!item] & """" ) ), a!fromJson( "{" & joinarray( local!listOfDifferences, "," ) & "}" ) )
What is the purpose of this code? Hand-crafting JSON is a bad idea in general.
MohammedIdrisKhan And what is the value of local!data?
like any data in db, I'm only concerned regarding the document type, that's where I'm getting the error, below is the value of field[Document:115497]; [Document:115501]
setting up a parameter in webAPIAny alternative that you'd want to suggest instead of Hand-crafting JSON?