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.
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), "/*/*")),
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)
The snippet returns a list of the field names, just like a!keys() does. I highlighted the spot which you have to modify to refer to your data structure.
apply(xpathsnippet(_, "name(*)"), xpathsnippet(toxml(<YOUR_DATA_STRUCTURE>), "/*/*"))
Hi Stefan,
When we do toxml(<OUR_DATA>) it comes in below format,
<a:Variant xmlns:a="http://www.appian.com/ae/types/2009" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">{"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:Variant>
And when we apply the code that you have given replacing the ri!cdt with our value it gives us {}
I had to add backslashes to escape the quotes in field 2. But this is working.
a!localVariables( local!jsonString: "{ ""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"":"""" } }", local!appianType: a!fromJson(local!jsonString), a!flatten(apply(xpathsnippet(_, "name(*)"), xpathsnippet(toxml(local!appianType), "/*/*"))) )
We do not get the key-value pair with the above code. We only get the keys as output.
Sure. Check my first post!
In the first post we had to use a!keys() but with our Appian version it is not allowed. We use 21.1
Come on! You have a solution to get the fields on screen, and one to extract the field names without using a!keys(). Please combine the two!
Thank you!!