Hi All,
We have data stored in our DB in text format. But data added can either be text or json. We would need to display the same in the interface in proper format.
That is if data is in plain text we would show it as text and if it is in JSON, we would need to format it and show.
For eg : if data is stored as "XYZ" then we would show either in Rich text editor/text field as XYZ.
If data is stored as text (in actual it is a JSON) -
{"Field1":"Test","Field2":"value is "not editable" test it.","Field3":"314146282515","Timestamp":"2019-06-19T11:05:23.678+0000","Field4":"XYZ","Reason":"XYZ","Time":"2022-02-19T05:09:26.046+0000","Field5":"ABC","Field6":"yui","Value":"OK","Action":"","Field7":"[abcged]","Field8":"","Field9":{"Value1":"test","Value2":"Test","Value3":"Test","Value4":"Test","Value5":null,"Value6":[{"value":"C:","name":"instance"},{"value":"ty","name":"object"},{"value":"er46","name":"test"}],"Field9":300,"Periods":1,"Operator":"LessThanOrEqualTo","Field10":25.0,"Feild11":"ignore","Field12":""}}
Then it should be shown either in Rich text editor/text field as :
Field1 : "Test"
Field2 : "value is "not editable" test it."
so on... in dictionary format.
Please guide how to achieve the above.
Discussion posts and replies are publicly visible
a!localVariables( local!json: {"Field1":"Test","Field2":"value is ""not editable"" test it.","Field3":"314146282515","Timestamp":"2019-06-19T11:05:23.678+0000","Field4":"XYZ","Reason":"XYZ","Time":"2022-02-19T05:09:26.046+0000","Field5":"ABC","Field6":"yui","Value":"OK","Action":"","Field7":"[abcged]","Field8":"","Field9":{"Value1":"test","Value2":"Test","Value3":"Test","Value4":"Test","Value5":null,"Value6":{{"value":"C:","name":"instance"},{"value":"ty","name":"object"},{"value":"er46","name":"test"}},"Field9":300,"Periods":1,"Operator":"LessThanOrEqualTo","Field10":25.0,"Feild11":"ignore","Field12":""}}, a!forEach( items: a!keys(local!json), expression: a!textField( label: fv!item, labelPosition: "JUSTIFIED", value: local!json[fv!item], readOnly: true ) ) )
You might have to add recursion to also display nested structures.
Thank you. One more question will it work for a normal text field also?is there any way how we can do a check whether the data is in text format or json?
Not a full proof idea tho but you can check if the string starts and ends with a curly brace then it is a JSON else it is a text. If that is a JSON, then you can use the fromJson() function to convert JSON to a dictionary.
Thank you!!
community.appian.com/.../json-validator
Thanks a lot!!
Hi
We use Appian version 21.1 where a!keys() is not supported. Any suggestion for our query posted above?
apply(xpathsnippet(_, "name(*)"), xpathsnippet(toxml(ri!cdt), "/*/*")),
Hi Harshit,
We can parse the data but how can we show it in interface? We use Appian 21.1 version
Can you please let us know what values should be kept in place of name(*) and what is ri!cdt? And should we call this code inside a rich text editor or paragraph ( as our data comes in bulk we cannot use text editor only)