Highlighted
Super Contributor.
Super Contributor.
611 views

JSON Parsing - Using IDM-ECMAlib

Hi,

I do know that the IDM-ECMAlib from https://github.com/fchierad/IDM-ECMAlib is not a Micro Focus offering. It does however seem very cool.
I am also aware that people in here possess extraordinarily high skills in this area (as well as being very friendly and helpful).

I have read the cool solution at https://www.netiq.com/communities/cool-solutions/cool_tools/easier-json-processing-idm-driver-policies/, and it have helped me, in sending stuff to a rest service, in JSON. So far so good.

Now I need to fetch entitites from the service, they are returned in JSON, looking like this:

{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}

We see two entities "Dommedagsprofet" and "Numismatiker".

I would like to make two adds out of this in xds.
Unfortunately, this is where I fail.

My understanding is that I should do like this
1) Make the JSON doc into an object with JSONparse()
2) Make the result of that into a nodeset with arrayToNodeset()
3) Loop over the element nodes in the nodeset
4) When the above works, extract the info from each entry with JSONget

Somehow, I fail. And I cannot see what I am doing wrong.

The rule I have been playing with, currently looks like this:



<?xml version="1.0" encoding="UTF-8"?><policy xmlns:js="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.rest.common.JSONConverter" xmlns:nexus="http://www.novell.com/nxsl/java/pwc.KMDNexusAPI">
<rule>
<description>Drop wot is not Queries</description>
<conditions>
<and>
<if-operation mode="nocase" op="not-equal">query</if-operation>
</and>
</conditions>
<actions>
<do-break/>
</actions>
</rule>
<rule>
<description>getRoles</description>
<conditions>
<and/>
</conditions>
<actions>
<do-set-local-variable disabled="true" name="lResult" notrace="true" scope="policy">
<arg-string>
<token-xpath expression="nexus:GetActiveRoles()"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="lResult" scope="policy">
<arg-string>
<token-text xml:space="preserve">{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}</token-text>
</arg-string>
</do-set-local-variable>
</actions>
</rule>
<rule>
<description>Parse Result</description>
<conditions>
<and>
<if-local-variable mode="regex" name="lResult" op="equal">.+</if-local-variable>
</and>
</conditions>
<actions>
<do-set-local-variable name="var_array" scope="policy">
<arg-object>
<token-xpath expression="es:JSONparse($lResult)"/>
</arg-object>
</do-set-local-variable>
<do-set-local-variable name="var_ns_array" scope="policy">
<arg-node-set>
<token-xpath expression="es:arrayToNodeset( $var_array )"/>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-xpath expression="es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element"/>
</arg-node-set>
<arg-actions>
<do-trace-message>
<arg-string>
<token-local-variable name="current-node"/>
</arg-string>
</do-trace-message>
</arg-actions>
</do-for-each>
<do-veto/>
</actions>
</rule>
</policy>


And the resulting trace looks like this:
LB-NXR01 ST:Applying input transformation policies.
LB-NXR01 ST:Applying policy: %+C%14Citp-Init%-C.
LB-NXR01 ST: Applying to query #1.
LB-NXR01 ST: Evaluating selection criteria for rule 'Drop wot is not Queries'.
LB-NXR01 ST: (if-operation not-equal "query") = FALSE.
LB-NXR01 ST: Rule rejected.
LB-NXR01 ST: Evaluating selection criteria for rule 'getRoles'.
LB-NXR01 ST: Rule selected.
LB-NXR01 ST: Applying rule 'getRoles'.
LB-NXR01 ST: Action: do-set-local-variable("lResult",scope="policy","{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}").
LB-NXR01 ST: arg-string("{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}")
LB-NXR01 ST: token-text("{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}")
LB-NXR01 ST: Arg Value: "{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}".
LB-NXR01 ST: Evaluating selection criteria for rule 'Parse Result'.
LB-NXR01 ST: (if-local-variable 'lResult' match ".+") = TRUE.
LB-NXR01 ST: Rule selected.
LB-NXR01 ST: Applying rule 'Parse Result'.
LB-NXR01 ST: Action: do-set-local-variable("var_array",scope="policy",arg-object(token-xpath("es:JSONparse($lResult)"))).
LB-NXR01 ST: arg-object(token-xpath("es:JSONparse($lResult)"))
LB-NXR01 ST: token-xpath("es:JSONparse($lResult)")
LB-NXR01 ST: Action: do-set-local-variable("var_ns_array",scope="policy",arg-node-set(token-xpath("es:arrayToNodeset( $var_array )"))).
LB-NXR01 ST: arg-node-set(token-xpath("es:arrayToNodeset( $var_array )"))
LB-NXR01 ST: token-xpath("es:arrayToNodeset( $var_array )")
LB-NXR01 ST: Token Value: {<array>}.
LB-NXR01 ST: Arg Value: {<array>}.
LB-NXR01 ST: Action: do-for-each(arg-node-set(token-xpath("es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element"))).
LB-NXR01 ST: arg-node-set(token-xpath("es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element"))
LB-NXR01 ST: token-xpath("es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element")
LB-NXR01 ST: Token Value: {}.
LB-NXR01 ST: Arg Value: {}.
LB-NXR01 ST: Action: do-veto().
LB-NXR01 ST:Policy returned:


It is obvious from the above trace, that I am not looping over the nodeset. Can anyone help me out, and point out where I am failing, and why?
Labels (1)
Tags (2)
0 Likes
3 Replies
Highlighted
Absent Member.
Absent Member.

Hi,

Seems like what is being returned by the service is not a valid JSON
array. Here is where you can check the spec: http://www.json.org/ .

For the input to be an array we'd expect it to have [ and ] around it
like this:
[{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}]


Cheers,

-Fernando

On 7/26/2018 2:34 AM, 6525036 wrote:
>
> Hi,
>
> I do know that the IDM-ECMAlib from
> https://github.com/fchierad/IDM-ECMAlib is not a Micro Focus offering.
> It does however seem very cool.
> I am also aware that people in here possess extraordinarily high skills
> in this area (as well as being very friendly and helpful).
>
> I have read the cool solution at
> https://www.netiq.com/communities/cool-solutions/cool_tools/easier-json-processing-idm-driver-policies/,
> and it have helped me, in sending stuff to a rest service, in JSON. So
> far so good.
>
> Now I need to fetch entitites from the service, they are returned in
> JSON, looking like this:
>
> {"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}
>
> We see two entities "Dommedagsprofet" and "Numismatiker".
>
> I would like to make two adds out of this in xds.
> Unfortunately, this is where I fail.
>
> My understanding is that I should do like this
> 1) Make the JSON doc into an object with JSONparse()
> 2) Make the result of that into a nodeset with arrayToNodeset()
> 3) Loop over the element nodes in the nodeset
> 4) When the above works, extract the info from each entry with JSONget
>
> Somehow, I fail. And I cannot see what I am doing wrong.
>
> The rule I have been playing with, currently looks like this:
>
>
>
>
> Code:
> --------------------
> <?xml version="1.0" encoding="UTF-8"?><policy xmlns:js="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.rest.common.JSONConverter" xmlns:nexus="http://www.novell.com/nxsl/java/pwc.KMDNexusAPI">
> <rule>
> <description>Drop wot is not Queries</description>
> <conditions>
> <and>
> <if-operation mode="nocase" op="not-equal">query</if-operation>
> </and>
> </conditions>
> <actions>
> <do-break/>
> </actions>
> </rule>
> <rule>
> <description>getRoles</description>
> <conditions>
> <and/>
> </conditions>
> <actions>
> <do-set-local-variable disabled="true" name="lResult" notrace="true" scope="policy">
> <arg-string>
> <token-xpath expression="nexus:GetActiveRoles()"/>
> </arg-string>
> </do-set-local-variable>
> <do-set-local-variable name="lResult" scope="policy">
> <arg-string>
> <token-text xml:space="preserve">{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}</token-text>
> </arg-string>
> </do-set-local-variable>
> </actions>
> </rule>
> <rule>
> <description>Parse Result</description>
> <conditions>
> <and>
> <if-local-variable mode="regex" name="lResult" op="equal">.+</if-local-variable>
> </and>
> </conditions>
> <actions>
> <do-set-local-variable name="var_array" scope="policy">
> <arg-object>
> <token-xpath expression="es:JSONparse($lResult)"/>
> </arg-object>
> </do-set-local-variable>
> <do-set-local-variable name="var_ns_array" scope="policy">
> <arg-node-set>
> <token-xpath expression="es:arrayToNodeset( $var_array )"/>
> </arg-node-set>
> </do-set-local-variable>
> <do-for-each>
> <arg-node-set>
> <token-xpath expression="es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element"/>
> </arg-node-set>
> <arg-actions>
> <do-trace-message>
> <arg-string>
> <token-local-variable name="current-node"/>
> </arg-string>
> </do-trace-message>
> </arg-actions>
> </do-for-each>
> <do-veto/>
> </actions>
> </rule>
> </policy>
> --------------------
>
>
> And the resulting trace looks like this:
>
> Code:
> --------------------
> LB-NXR01 ST:Applying input transformation policies.
> LB-NXR01 ST:Applying policy: %+C%14Citp-Init%-C.
> LB-NXR01 ST: Applying to query #1.
> LB-NXR01 ST: Evaluating selection criteria for rule 'Drop wot is not Queries'.
> LB-NXR01 ST: (if-operation not-equal "query") = FALSE.
> LB-NXR01 ST: Rule rejected.
> LB-NXR01 ST: Evaluating selection criteria for rule 'getRoles'.
> LB-NXR01 ST: Rule selected.
> LB-NXR01 ST: Applying rule 'getRoles'.
> LB-NXR01 ST: Action: do-set-local-variable("lResult",scope="policy","{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}").
> LB-NXR01 ST: arg-string("{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}")
> LB-NXR01 ST: token-text("{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}")
> LB-NXR01 ST: Arg Value: "{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}".
> LB-NXR01 ST: Evaluating selection criteria for rule 'Parse Result'.
> LB-NXR01 ST: (if-local-variable 'lResult' match ".+") = TRUE.
> LB-NXR01 ST: Rule selected.
> LB-NXR01 ST: Applying rule 'Parse Result'.
> LB-NXR01 ST: Action: do-set-local-variable("var_array",scope="policy",arg-object(token-xpath("es:JSONparse($lResult)"))).
> LB-NXR01 ST: arg-object(token-xpath("es:JSONparse($lResult)"))
> LB-NXR01 ST: token-xpath("es:JSONparse($lResult)")
> LB-NXR01 ST: Action: do-set-local-variable("var_ns_array",scope="policy",arg-node-set(token-xpath("es:arrayToNodeset( $var_array )"))).
> LB-NXR01 ST: arg-node-set(token-xpath("es:arrayToNodeset( $var_array )"))
> LB-NXR01 ST: token-xpath("es:arrayToNodeset( $var_array )")
> LB-NXR01 ST: Token Value: {<array>}.
> LB-NXR01 ST: Arg Value: {<array>}.
> LB-NXR01 ST: Action: do-for-each(arg-node-set(token-xpath("es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element"))).
> LB-NXR01 ST: arg-node-set(token-xpath("es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element"))
> LB-NXR01 ST: token-xpath("es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element")
> LB-NXR01 ST: Token Value: {}.
> LB-NXR01 ST: Arg Value: {}.
> LB-NXR01 ST: Action: do-veto().
> LB-NXR01 ST:Policy returned:
> --------------------
>
>
> It is obvious from the above trace, that I am not looping over the
> nodeset. Can anyone help me out, and point out where I am failing, and
> why?
>
>


0 Likes
Highlighted
Absent Member.
Absent Member.

Updated policy's input JSON string and loop as well:

<policy xmlns:js="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.rest.common.JSONConverter" xmlns:nexus="http://www.novell.com/nxsl/java/pwc.KMDNexusAPI">
<rule>
<description>Drop wot is not Queries</description>
<conditions>
<and>
<if-operation mode="nocase" op="not-equal">query</if-operation>
</and>
</conditions>
<actions>
<do-break/>
</actions>
</rule>
<rule>
<description>getRoles</description>
<conditions>
<and/>
</conditions>
<actions>
<do-set-local-variable disabled="true" name="lResult" notrace="true" scope="policy">
<arg-string>
<token-xpath expression="nexus:GetActiveRoles()"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="lResult" scope="policy">
<arg-string>
<token-text xml:space="preserve">[{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}]</token-text>
</arg-string>
</do-set-local-variable>
</actions>
</rule>
<rule>
<description>Parse Result</description>
<conditions>
<and>
<if-local-variable mode="regex" name="lResult" op="equal">.+</if-local-variable>
</and>
</conditions>
<actions>
<do-set-local-variable name="var_array" scope="policy">
<arg-object>
<token-xpath expression="es:JSONparse($lResult)"/>
</arg-object>
</do-set-local-variable>
<do-set-local-variable name="var_ns_array" scope="policy">
<arg-node-set>
<token-xpath expression="es:arrayToNodeset( $var_array )"/>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-xpath expression="$var_ns_array/element"/>
</arg-node-set>
<arg-actions>
<do-set-local-variable name="var_ns_current-node" scope="policy">
<arg-object>
<token-xpath expression="es:JSONparse( $current-node )"/>
</arg-object>
</do-set-local-variable>
<do-trace-message>
<arg-string>
<token-xpath expression="es:JSONget( $var_ns_current-node, 'id' )"/>
</arg-string>
</do-trace-message>
<do-trace-message>
<arg-string>
<token-xpath expression="es:JSONget( es:JSONparse( $current-node ), 'name' )"/>
</arg-string>
</do-trace-message>
</arg-actions>
</do-for-each>
<do-veto/>
</actions>
</rule>
</policy>

trace excerpt:

Policytest :Applying policy: %+C%14Cforumtest%-C.
Policytest : Applying to query #1.
Policytest : Evaluating selection criteria for rule 'Drop wot is not Queries'.
Policytest : (if-operation not-equal "query") = FALSE.
Policytest : Rule rejected.
Policytest : Evaluating selection criteria for rule 'getRoles'.
Policytest : Rule selected.
Policytest : Applying rule 'getRoles'.
Policytest : Action: do-set-local-variable("lResult",scope="policy","[{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}]").
Policytest : arg-string("[{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}]")
Policytest : token-text("[{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}]")
Policytest : Arg Value: "[{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}]".
Policytest : Evaluating selection criteria for rule 'Parse Result'.
Policytest : (if-local-variable 'lResult' match ".+") = TRUE.
Policytest : Rule selected.
Policytest : Applying rule 'Parse Result'.
Policytest : Action: do-set-local-variable("var_array",scope="policy",arg-object(token-xpath("es:JSONparse($lResult)"))).
Policytest : arg-object(token-xpath("es:JSONparse($lResult)"))
Policytest : token-xpath("es:JSONparse($lResult)")
Policytest : Action: do-set-local-variable("var_ns_array",scope="policy",arg-node-set(token-xpath("es:arrayToNodeset( $var_array )"))).
Policytest : arg-node-set(token-xpath("es:arrayToNodeset( $var_array )"))
Policytest : token-xpath("es:arrayToNodeset( $var_array )")
Policytest : Token Value: {<array>}.
Policytest : Arg Value: {<array>}.
Policytest : Action: do-for-each(arg-node-set(token-xpath("$var_ns_array/element"))).
Policytest : arg-node-set(token-xpath("$var_ns_array/element"))
Policytest : token-xpath("$var_ns_array/element")
Policytest : Token Value: {<element>,<element>}.
Policytest : Arg Value: {<element>,<element>}.
Policytest : Performing actions for local-variable(current-node) = <element>.
Policytest : Action: do-set-local-variable("var_ns_current-node",scope="policy",arg-object(token-xpath("es:JSONparse( $current-node )"))).
Policytest : arg-object(token-xpath("es:JSONparse( $current-node )"))
Policytest : token-xpath("es:JSONparse( $current-node )")
Policytest : Action: do-trace-message(token-xpath("es:JSONget( $var_ns_current-node, 'id' )")).
Policytest : arg-string(token-xpath("es:JSONget( $var_ns_current-node, 'id' )"))
Policytest : token-xpath("es:JSONget( $var_ns_current-node, 'id' )")
Policytest : ECMA debug: JSONget(): Parsing: "id", type: string
Policytest : Token Value: "691".
Policytest : Arg Value: "691".
Policytest :691
Policytest : Action: do-trace-message(token-xpath("es:JSONget( es:JSONparse( $current-node ), 'name' )")).
Policytest : arg-string(token-xpath("es:JSONget( es:JSONparse( $current-node ), 'name' )"))
Policytest : token-xpath("es:JSONget( es:JSONparse( $current-node ), 'name' )")
Policytest : ECMA debug: JSONget(): Parsing: "name", type: string
Policytest : Token Value: "Dommedagsprofet".
Policytest : Arg Value: "Dommedagsprofet".
Policytest :Dommedagsprofet
Policytest : Performing actions for local-variable(current-node) = <element>.
Policytest : Action: do-set-local-variable("var_ns_current-node",scope="policy",arg-object(token-xpath("es:JSONparse( $current-node )"))).
Policytest : arg-object(token-xpath("es:JSONparse( $current-node )"))
Policytest : token-xpath("es:JSONparse( $current-node )")
Policytest : Action: do-trace-message(token-xpath("es:JSONget( $var_ns_current-node, 'id' )")).
Policytest : arg-string(token-xpath("es:JSONget( $var_ns_current-node, 'id' )"))
Policytest : token-xpath("es:JSONget( $var_ns_current-node, 'id' )")
Policytest : ECMA debug: JSONget(): Parsing: "id", type: string
Policytest : Token Value: "2562".
Policytest : Arg Value: "2562".
Policytest :2562
Policytest : Action: do-trace-message(token-xpath("es:JSONget( es:JSONparse( $current-node ), 'name' )")).
Policytest : arg-string(token-xpath("es:JSONget( es:JSONparse( $current-node ), 'name' )"))
Policytest : token-xpath("es:JSONget( es:JSONparse( $current-node ), 'name' )")
Policytest : ECMA debug: JSONget(): Parsing: "name", type: string
Policytest : Token Value: "Numismatiker".
Policytest : Arg Value: "Numismatiker".
Policytest :Numismatiker
Policytest : Action: do-veto().

Inside the loop there are 2 different approaches on the traces to show them both working. First was to save the current-node parsing into object in a variable then using the local variable inside the JSONget, second was to layer the es:JSONparse inside of the get as the first parameter. For a single value both have the same performance, for multiple JSONget in a row the first one has better performance.

Cheers,

-Fernando


On 7/26/2018 2:34 AM, 6525036 wrote:
>
> Hi,
>
> I do know that the IDM-ECMAlib from
> https://github.com/fchierad/IDM-ECMAlib is not a Micro Focus offering.
> It does however seem very cool.
> I am also aware that people in here possess extraordinarily high skills
> in this area (as well as being very friendly and helpful).
>
> I have read the cool solution at
> https://www.netiq.com/communities/cool-solutions/cool_tools/easier-json-processing-idm-driver-policies/,
> and it have helped me, in sending stuff to a rest service, in JSON. So
> far so good.
>
> Now I need to fetch entitites from the service, they are returned in
> JSON, looking like this:
>
> {"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}
>
> We see two entities "Dommedagsprofet" and "Numismatiker".
>
> I would like to make two adds out of this in xds.
> Unfortunately, this is where I fail.
>
> My understanding is that I should do like this
> 1) Make the JSON doc into an object with JSONparse()
> 2) Make the result of that into a nodeset with arrayToNodeset()
> 3) Loop over the element nodes in the nodeset
> 4) When the above works, extract the info from each entry with JSONget
>
> Somehow, I fail. And I cannot see what I am doing wrong.
>
> The rule I have been playing with, currently looks like this:
>
>
>
>
> Code:
> --------------------
> <?xml version="1.0" encoding="UTF-8"?><policy xmlns:js="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.rest.common.JSONConverter" xmlns:nexus="http://www.novell.com/nxsl/java/pwc.KMDNexusAPI">
> <rule>
> <description>Drop wot is not Queries</description>
> <conditions>
> <and>
> <if-operation mode="nocase" op="not-equal">query</if-operation>
> </and>
> </conditions>
> <actions>
> <do-break/>
> </actions>
> </rule>
> <rule>
> <description>getRoles</description>
> <conditions>
> <and/>
> </conditions>
> <actions>
> <do-set-local-variable disabled="true" name="lResult" notrace="true" scope="policy">
> <arg-string>
> <token-xpath expression="nexus:GetActiveRoles()"/>
> </arg-string>
> </do-set-local-variable>
> <do-set-local-variable name="lResult" scope="policy">
> <arg-string>
> <token-text xml:space="preserve">{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}</token-text>
> </arg-string>
> </do-set-local-variable>
> </actions>
> </rule>
> <rule>
> <description>Parse Result</description>
> <conditions>
> <and>
> <if-local-variable mode="regex" name="lResult" op="equal">.+</if-local-variable>
> </and>
> </conditions>
> <actions>
> <do-set-local-variable name="var_array" scope="policy">
> <arg-object>
> <token-xpath expression="es:JSONparse($lResult)"/>
> </arg-object>
> </do-set-local-variable>
> <do-set-local-variable name="var_ns_array" scope="policy">
> <arg-node-set>
> <token-xpath expression="es:arrayToNodeset( $var_array )"/>
> </arg-node-set>
> </do-set-local-variable>
> <do-for-each>
> <arg-node-set>
> <token-xpath expression="es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element"/>
> </arg-node-set>
> <arg-actions>
> <do-trace-message>
> <arg-string>
> <token-local-variable name="current-node"/>
> </arg-string>
> </do-trace-message>
> </arg-actions>
> </do-for-each>
> <do-veto/>
> </actions>
> </rule>
> </policy>
> --------------------
>
>
> And the resulting trace looks like this:
>
> Code:
> --------------------
> LB-NXR01 ST:Applying input transformation policies.
> LB-NXR01 ST:Applying policy: %+C%14Citp-Init%-C.
> LB-NXR01 ST: Applying to query #1.
> LB-NXR01 ST: Evaluating selection criteria for rule 'Drop wot is not Queries'.
> LB-NXR01 ST: (if-operation not-equal "query") = FALSE.
> LB-NXR01 ST: Rule rejected.
> LB-NXR01 ST: Evaluating selection criteria for rule 'getRoles'.
> LB-NXR01 ST: Rule selected.
> LB-NXR01 ST: Applying rule 'getRoles'.
> LB-NXR01 ST: Action: do-set-local-variable("lResult",scope="policy","{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}").
> LB-NXR01 ST: arg-string("{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}")
> LB-NXR01 ST: token-text("{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}")
> LB-NXR01 ST: Arg Value: "{"_organisationId":"3","name":"Dommedagsprofet","active":true,"id":691},{"_organisationId":"3","name":"Numismatiker","active":true,"id":2562}".
> LB-NXR01 ST: Evaluating selection criteria for rule 'Parse Result'.
> LB-NXR01 ST: (if-local-variable 'lResult' match ".+") = TRUE.
> LB-NXR01 ST: Rule selected.
> LB-NXR01 ST: Applying rule 'Parse Result'.
> LB-NXR01 ST: Action: do-set-local-variable("var_array",scope="policy",arg-object(token-xpath("es:JSONparse($lResult)"))).
> LB-NXR01 ST: arg-object(token-xpath("es:JSONparse($lResult)"))
> LB-NXR01 ST: token-xpath("es:JSONparse($lResult)")
> LB-NXR01 ST: Action: do-set-local-variable("var_ns_array",scope="policy",arg-node-set(token-xpath("es:arrayToNodeset( $var_array )"))).
> LB-NXR01 ST: arg-node-set(token-xpath("es:arrayToNodeset( $var_array )"))
> LB-NXR01 ST: token-xpath("es:arrayToNodeset( $var_array )")
> LB-NXR01 ST: Token Value: {<array>}.
> LB-NXR01 ST: Arg Value: {<array>}.
> LB-NXR01 ST: Action: do-for-each(arg-node-set(token-xpath("es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element"))).
> LB-NXR01 ST: arg-node-set(token-xpath("es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element"))
> LB-NXR01 ST: token-xpath("es:arrayToNodeset(es:JSONget($var_ns_array,'name.id'))/element")
> LB-NXR01 ST: Token Value: {}.
> LB-NXR01 ST: Arg Value: {}.
> LB-NXR01 ST: Action: do-veto().
> LB-NXR01 ST:Policy returned:
> --------------------
>
>
> It is obvious from the above trace, that I am not looping over the
> nodeset. Can anyone help me out, and point out where I am failing, and
> why?
>
>


0 Likes
Highlighted
Super Contributor.
Super Contributor.

Aaahhhh.... answering myself here.
If I make the JSON into an array by giving it square brackets around, it does seem to work a lot better.
By using the Policy Simulator, I could see that the ecma functions said "this is not an ECMA array" (more or less, tht was the meaning of it anyway).
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.