sivaramtm Super Contributor.
Super Contributor.
566 views

Help with parsing rest json response to XDS

Jump to solution

Hi,

Please find the below response from servicenow rest end point and help to parse it as nds attributes.

<nds dtdversion="3.5" ndsversion="8.x">
<source>
<product build="20170130_0359" instance="Rest-ServicenowDW" version="1.0.0.1">Identity Manager REST Driver</product>
<contact>NetIQ Corporation.</contact>
</source>
<input>
<driver-operation-data class-name="" command="poll" event-id="Rest-ServicenowDW##119659145##0">
<response>
{"result":[{"banner_image_light":"","country":"DK","parent":{"display_value":"","link":"http://servicenow-test.BBC.cc/api/now/table/core_company/true"},"notes":"","stock_symbol":"","u_logopath":"","discount":"","u_kundenr":"1015425","sys_updated_on":"07.05.2019 04:47:12","apple_icon":"","sys_updated_by":"BBC_POB","u_customer_alias":"","fiscal_year":"","sso_source":"","sys_created_on":"06.10.2016 13:18:52","contact":"","sys_domain":{"display_value":"TOP/MSP/BBC","link":"http://servicenow-test.BBC.dk/api/now/table/domain/4c346138a44f12005821241c95d66248"},"u_problem_coordinator":{"display_value":"PROBLEM","link":"http://servicenow-test.BBC.dk/api/now/table/sys_user_group/b4dab65fff02220028765dff7fa4adc7"},"stock_price":"","banner_image":"","state":"","sys_created_by":"RestMQUser","longitude":"","zip":"8500","profits":"kr 0,00","active":"true","sys_domain_path":"!!!/!!#/!!$/","fax_phone":"","phone":"86326632","banner_text":"","name":"Børnehaven Regnbuen","primary":"false","city":"Grenaa","latitude":"","u_company_code":"","sys_class_name":"Account","manufacturer":"false","sys_id":"00067ea5ff9a220072816dff7fa4ad17","market_cap":"kr 0,00","num_employees":"","rank_tier":null,"street":"Lupinskrænten 6","vendor":"false","lat_long_error":"","u_ssoidentifier":"","vendor_type":"","u_ean_number":"","revenue_per_year":"kr 0,00","website":"","publicly_traded":"false","sys_mod_count":"5","u_email_domain":"","sys_tags":"","vendor_manager":"","customer":"false"}]}
</response>
</driver-operation-data>
</input>
</nds>

Thanks

Siva ram T

Labels (1)
0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Re: Help with parsing rest json response to XDS

Jump to solution

So the JavaScript Engine used in IDM doesn't yet like for..of. These needs to be changed to classic for loop and for..in.

Also the appendChild calls need to be in the inner loop.

I've edited the my original post.

This gives me

<status level="success" type="app-general">number of responses: 1</status>
<instance src-dn="1015425">
	<attr attr-name="banner_image_light">
		<value></value>
	</attr>
	<attr attr-name="country">
		<value>DK</value>
	</attr>
	<attr attr-name="parent">
		<value>{"display_value":"","link":"http://servicenow-test.BBC.dk/api/now/table/core_company/true"}</value>
	</attr>
	<attr attr-name="notes">
		<value></value>
	</attr>
	<attr attr-name="stock_symbol">
		<value></value>
	</attr>
	<attr attr-name="u_logopath">
		<value></value>
	</attr>
	<attr attr-name="discount">
		<value></value>
	</attr>
	<attr attr-name="u_kundenr">
		<value>1015425</value>
	</attr>
	<attr attr-name="sys_updated_on">
		<value>07.05.2019 04:47:12</value>
	</attr>
	<attr attr-name="apple_icon">
		<value></value>
	</attr>
	<attr attr-name="sys_updated_by">
		<value>BBC_POB</value>
	</attr>
	<attr attr-name="u_customer_alias">
		<value></value>
	</attr>
	<attr attr-name="fiscal_year">
		<value></value>
	</attr>
	<attr attr-name="sso_source">
		<value></value>
	</attr>
	<attr attr-name="sys_created_on">
		<value>06.10.2016 13:18:52</value>
	</attr>
	<attr attr-name="contact">
		<value></value>
	</attr>
	<attr attr-name="sys_domain">
		<value>{"display_value":"TOP/MSP/BBC","link":"http://servicenow-test.BBC.dk/api/now/table/domain/4c346138a44f12005821241c95d66248"}</value>
	</attr>
	<attr attr-name="u_problem_coordinator">
		<value>{"display_value":"PROBLEM","link":"http://servicenow-test.BBC.dk/api/now/table/sys_user_group/b4dab65fff02220028765dff7fa4adc7"}</value>
	</attr>
	<attr attr-name="stock_price">
		<value></value>
	</attr>
	<attr attr-name="banner_image">
		<value></value>
	</attr>
	<attr attr-name="state">
		<value></value>
	</attr>
	<attr attr-name="sys_created_by">
		<value>RestMQUser</value>
	</attr>
	<attr attr-name="longitude">
		<value></value>
	</attr>
	<attr attr-name="zip">
		<value>8500</value>
	</attr>
	<attr attr-name="profits">
		<value>kr 0,00</value>
	</attr>
	<attr attr-name="active">
		<value>true</value>
	</attr>
	<attr attr-name="sys_domain_path">
		<value>!!!/!!#/!!$/</value>
	</attr>
	<attr attr-name="fax_phone">
		<value></value>
	</attr>
	<attr attr-name="phone">
		<value>86326632</value>
	</attr>
	<attr attr-name="banner_text">
		<value></value>
	</attr>
	<attr attr-name="name">
		<value>Børnehaven Regnbuen</value>
	</attr>
	<attr attr-name="primary">
		<value>false</value>
	</attr>
	<attr attr-name="city">
		<value>Grenaa</value>
	</attr>
	<attr attr-name="latitude">
		<value></value>
	</attr>
	<attr attr-name="u_company_code">
		<value></value>
	</attr>
	<attr attr-name="sys_class_name">
		<value>Account</value>
	</attr>
	<attr attr-name="manufacturer">
		<value>false</value>
	</attr>
	<attr attr-name="sys_id">
		<value>00067ea5ff9a220072816dff7fa4ad17</value>
	</attr>
	<attr attr-name="market_cap">
		<value>kr 0,00</value>
	</attr>
	<attr attr-name="num_employees">
		<value></value>
	</attr>
	<attr attr-name="rank_tier">
		<value>null</value>
	</attr>
	<attr attr-name="street">
		<value>Lupinskrænten 6</value>
	</attr>
	<attr attr-name="vendor">
		<value>false</value>
	</attr>
	<attr attr-name="lat_long_error">
		<value></value>
	</attr>
	<attr attr-name="u_ssoidentifier">
		<value></value>
	</attr>
	<attr attr-name="vendor_type">
		<value></value>
	</attr>
	<attr attr-name="u_ean_number">
		<value></value>
	</attr>
	<attr attr-name="revenue_per_year">
		<value>kr 0,00</value>
	</attr>
	<attr attr-name="website">
		<value></value>
	</attr>
	<attr attr-name="publicly_traded">
		<value>false</value>
	</attr>
	<attr attr-name="sys_mod_count">
		<value>5</value>
	</attr>
	<attr attr-name="u_email_domain">
		<value></value>
	</attr>
	<attr attr-name="sys_tags">
		<value></value>
	</attr>
	<attr attr-name="vendor_manager">
		<value></value>
	</attr>
	<attr attr-name="customer">
		<value>false</value>
	</attr>
</instance>

 

0 Likes
22 Replies
Knowledge Partner
Knowledge Partner

Re: Help with parsing rest json response to XDS

Jump to solution

First things firsts, find a JSON Formatting web site you like and format it so it is readable:

 

{

    "result":[
        {
            "banner_image_light":"",
            "country":"DK",
            "parent":{
                "display_value":"",
                "link":"<a href="http://servicenow-test.BBC.cc/api/now/table/core_company/true" target="_blank">http://servicenow-test.BBC.cc/api/now/table/core_company/true</a>"
            },
            "notes":"",
            "stock_symbol":"",
            "u_logopath":"",
            "discount":"",
            "u_kundenr":"1015425",
            "sys_updated_on":"07.05.2019 04:47:12",
            "apple_icon":"",
            "sys_updated_by":"BBC_POB",
            "u_customer_alias":"",
            "fiscal_year":"",
            "sso_source":"",
            "sys_created_on":"06.10.2016 13:18:52",
            "contact":"",
            "sys_domain":{
                "display_value":"TOP/MSP/BBC",
                "link":"<a href="http://servicenow-test.BBC.dk/api/now/table/domain/4c346138a44f12005821241c95d66248" target="_blank">http://servicenow-test.BBC.dk/api/now/table/domain/4c346138a44f12005821241c95d66248</a>"
            },
            "u_problem_coordinator":{
                "display_value":"PROBLEM",
                "link":"<a href="http://servicenow-test.BBC.dk/api/now/table/sys_user_group/b4dab65fff02220028765dff7fa4adc7" target="_blank">http://servicenow-test.BBC.dk/api/now/table/sys_user_group/b4dab65fff02220028765dff7fa4adc7</a>"
            },
            "stock_price":"",
            "banner_image":"",
            "state":"",
            "sys_created_by":"RestMQUser",
            "longitude":"",
            "zip":"8500",
            "profits":"kr 0,00",
            "active":"true",
            "sys_domain_path":"!!!/!!#/!!$/",
            "fax_phone":"",
            "phone":"86326632",
            "banner_text":"",
            "name":"Børnehaven Regnbuen",
            "primary":"false",
            "city":"Grenaa",
            "latitude":"",
            "u_company_code":"",
            "sys_class_name":"Account",
            "manufacturer":"false",
            "sys_id":"00067ea5ff9a220072816dff7fa4ad17",
            "market_cap":"kr 0,00",
            "num_employees":"",
            "rank_tier":null,
            "street":"Lupinskrænten 6",
            "vendor":"false",
            "lat_long_error":"",
            "u_ssoidentifier":"",
            "vendor_type":"",
            "u_ean_number":"",
            "revenue_per_year":"kr 0,00",
            "website":"",
            "publicly_traded":"false",
            "sys_mod_count":"5",
            "u_email_domain":"",
            "sys_tags":"",
            "vendor_manager":"",
            "customer":"false"
        }
    ]

}

 

 

Now you can start thinking about how to parse it.  That does not look like the format the built in Java classes in the REST driver can convert.  But you can do it in ECMA.

So get the result into a string variable.

set local variable DATA as XPATH of driver-operation-data/response/text()

Then you can do an ECMA expression of something like:

Set local variable NAME as XPATH of es:(JSON.parse($DATA).result.name

 

I think that should work.

Then you could loop over the results or over a set of attrs you want, and get variables for each, or you could use the XML attribute/text tokens to build XML after it innto a instance or modify event document.

 

(Note: I am being wrned I have invalid HTML in here, so if formatting is all screwed up, well drat then).

0 Likes
sivaramtm Super Contributor.
Super Contributor.

Re: Help with parsing rest json response to XDS

Jump to solution
Thanks for the quick response. I applied the same and got the result like below. How to get the values from java object
[07/05/19 14:42:11.908]:Rest-SN PT:{"result":[{"banner_image_light":"","country":"DK","parent":{"display_value":"","link":"http://servicenow-test.BBC.dk/api/now/table/core_company/true"},"notes":"","stock_symbol":"","u_logopath":"","discount":"","u_kundenr":"1015425","sys_updated_on":"07.05.2019 04:47:12","apple_icon":"","sys_updated_by":"BBC_POB","u_customer_alias":"","fiscal_year":"","sso_source":"","sys_created_on":"06.10.2016 13:18:52","contact":"","sys_domain":{"display_value":"TOP/MSP/BBC","link":"http://servicenow-test.BBC.dk/api/now/table/domain/4c346138a44f12005821241c95d66248"},"u_problem_coordinator":{"display_value":"PROBLEM","link":"http://servicenow-test.BBC.dk/api/now/table/sys_user_group/b4dab65fff02220028765dff7fa4adc7"},"stock_price":"","banner_image":"","state":"","sys_created_by":"RestMQUser","longitude":"","zip":"8500","profits":"kr 0,00","active":"true","sys_domain_path":"!!!/!!#/!!$/","fax_phone":"","phone":"86326632","banner_text":"","name":"Børnehaven Regnbuen","primary":"false","city":"Grenaa","latitude":"","u_company_code":"","sys_class_name":"Account","manufacturer":"false","sys_id":"00067ea5ff9a220072816dff7fa4ad17","market_cap":"kr 0,00","num_employees":"","rank_tier":null,"street":"Lupinskrænten 6","vendor":"false","lat_long_error":"","u_ssoidentifier":"","vendor_type":"","u_ean_number":"","revenue_per_year":"kr 0,00","website":"","publicly_traded":"false","sys_mod_count":"5","u_email_domain":"","sys_tags":"","vendor_manager":"","customer":"false"}]}+++++Contenet of XML data++++
[07/05/19 14:42:11.908]:Rest-SN ST: Pumping XDS to eDirectory.
[07/05/19 14:42:11.924]:Rest-SN PT: Action: do-set-local-variable("lvname",scope="policy",token-xpath("es:JSONparse($data,'result.name')")).
[07/05/19 14:42:11.924]:Rest-SN ST: Performing operation modify for \BBCIDV\system\driverset1\Rest-ServicenowDW\PermissionEntMapping.
[07/05/19 14:42:11.924]:Rest-SN PT: arg-string(token-xpath("es:JSONparse($data,'result.name')"))
[07/05/19 14:42:11.924]:Rest-SN ST: --JCLNT-- \BBCIDV\system\driverset1\Rest-ServicenowDW : Duplicating : context = 1951400030, tempContext = 1951400158
[07/05/19 14:42:11.924]:Rest-SN PT: token-xpath("es:JSONparse($data,'result.name')")
[07/05/19 14:42:11.924]:Rest-SN ST: Modifying entry \BBCIDV\system\driverset1\Rest-ServicenowDW\PermissionEntMapping.
[07/05/19 14:42:11.924]:Rest-SN PT: Token Value: "com.novell.xsl.extensions.JavaObject@5120c915".
[07/05/19 14:42:11.924]:Rest-SN PT: Arg Value: "com.novell.xsl.extensions.JavaObject@5120c915".
[07/05/19 14:42:11.924]:Rest-SN PT: Action: do-trace-message(token-local-variable("lvname")+"+++++Contenet of lvname++++").
[07/05/19 14:42:11.924]:Rest-SN PT: arg-string(token-local-variable("lvname")+"+++++Contenet of lvname++++")
[07/05/19 14:42:11.924]:Rest-SN PT: token-local-variable("lvname")
[07/05/19 14:42:11.924]:Rest-SN PT: Token Value: "com.novell.xsl.extensions.JavaObject@5120c915".
0 Likes
Knowledge Partner
Knowledge Partner

Re: Help with parsing rest json response to XDS

Jump to solution

So I am not 100% sure how to pick out the name node from the JSON since it is inside an array.

So I would find consider opening an ECMA Object in Designer.

 

Then set a variable say "payload" with the text of your JSON.

Then JSON.parse($payload) and then play around with differing syntax to see which works

The good news is that the ECMA editor for ECMA Resources at the bottom third of the screen has a greater than sign, which is a command prompt and you can execute a function from there and test your ECMA. Much faster than in the engine. In theory the ECMA in Designer is the same interpreter in the engine so it should be a valid test.

Might be more like:
token-xpath("es:JSONparse($data,'result[0].name')

I would have to spend some time testing to be sure I got it correct. But you can do that for yourself.

 

 

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Help with parsing rest json response to XDS

Jump to solution

I find it easyest to do the JSON to XDS conversion in JavaScript. Define a function that takes JSON as input, parses it into a JS object then then use DOM methods to build an XDS document.

In this example I create a status element and an instance element for every array member of result:

 

 

 

/**
 * parse JSON returned by REST service and transform it into XDS elements
 * @Param {string} payload JSON encoded string
 * @return {NodeSet} input converted to a NodeSet
 */
function JSONtoXDS (payload) {
    var nodeSet = new Packages.com.novell.xml.xpath.NodeSet();
    var document = Packages.com.novell.xml.dom.DocumentFactory.newDocument();
    var statusElement = document.createElement('status');

    try {
        var response = JSON.parse(payload);
    } catch (e) {
        // parsing error
        statusElement.setAttributeNS(null, 'level', 'error');
        statusElement.setAttributeNS(null, 'type', 'driver-general');
        statusElement.appendChild(document.createTextNode(e.toString()));
        statusElement.appendChild(document.createTextNode(payload));
        nodeSet.add(statusElement);
        return (nodeSet);
    }

    if (Array.isArray(response.result)) {
        statusElement.setAttributeNS(null, 'level', 'success');
        statusElement.setAttributeNS(null, 'type', 'app-general');
        statusElement.appendChild(document.createTextNode('number of responses: ' + response.result.length));
        nodeSet.add(statusElement);

        // create the instance node
        for (var i = 0; i < response.result.length; i++) {
            var instanceElement = document.createElement('instance');
            instanceElement.setAttributeNS(null, 'src-dn', response.result[i]['u_kundenr']);
            for (var key in response.result[i]) {
                var attrElement = document.createElement('attr');
                attrElement.setAttributeNS(null, 'attr-name', key);
                var valueElement = document.createElement('value');
                var value = response.result[i][key];
                if (typeof value !== 'string') {
                    value = JSON.stringify(value);
                }
                valueElement.appendChild(document.createTextNode(value));
                attrElement.appendChild(valueElement);
                instanceElement.appendChild(attrElement);
            }
            nodeSet.add(instanceElement);
        }
    } else {
        // handle application specific error
        statusElement.setAttributeNS(null, 'level', 'error');
        statusElement.setAttributeNS(null, 'type', 'app-general');
        statusElement.appendChild(document.createTextNode('some error'));
        nodeSet.add(statusElement);
    }
    return (nodeSet);
}

 

Call the function from the input tranformation policy set like this to replace the current operation with the parsed one:

 

 

<policy xmlns:es='http://www.novell.com/nxsl/ecmascript'>
  <rule>
    <description>Translate JSON to XDS</description>
    <conditions>
      <and>
        <if-xpath op='true'>string-length(./driver-operation-data/response/value/text())>0</if-xpath>
      </and>
    </conditions>
    <actions>
      <do-set-local-variable name='lvResponse' scope='policy'>
        <arg-node-set>
          <token-xpath expression='es:JSONtoXDS(./driver-operation-data/response/value/text())'/>
        </arg-node-set>
      </do-set-local-variable>
      <do-clone-xpath dest-expression='..' src-expression='$lvResponse'/>
      <do-strip-xpath expression='$current-op'/>
    </actions>
  </rule>
</policy>

 

Knowledge Partner
Knowledge Partner

Re: Help with parsing rest json response to XDS

Jump to solution

Looks like your second part, the XML failed to render right.

I have an ECMA package I maintain for my stuff. Do you mind if I add your function to it?  (Of course add credit to you in it). 

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Help with parsing rest json response to XDS

Jump to solution

Hi Geoff,

thanks for pointing out the formatting error. I did a convert XML to text in VSCode and posted that as HTML/XML code in the forum.

Sure. Add it to your collection.

 

Norbert

0 Likes
sivaramtm Super Contributor.
Super Contributor.

Re: Help with parsing rest json response to XDS

Jump to solution
I tried creating the ecmascript with JSON toXDS content but getting syntax error in for loop. Can you please suggest.
0 Likes
Knowledge Partner
Knowledge Partner

Re: Help with parsing rest json response to XDS

Jump to solution

Ya me too. Code pasted is not quite complete.  I got it to run, but not work, still working on fixing it on my end.

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Help with parsing rest json response to XDS

Jump to solution

So the JavaScript Engine used in IDM doesn't yet like for..of. These needs to be changed to classic for loop and for..in.

Also the appendChild calls need to be in the inner loop.

I've edited the my original post.

This gives me

<status level="success" type="app-general">number of responses: 1</status>
<instance src-dn="1015425">
	<attr attr-name="banner_image_light">
		<value></value>
	</attr>
	<attr attr-name="country">
		<value>DK</value>
	</attr>
	<attr attr-name="parent">
		<value>{"display_value":"","link":"http://servicenow-test.BBC.dk/api/now/table/core_company/true"}</value>
	</attr>
	<attr attr-name="notes">
		<value></value>
	</attr>
	<attr attr-name="stock_symbol">
		<value></value>
	</attr>
	<attr attr-name="u_logopath">
		<value></value>
	</attr>
	<attr attr-name="discount">
		<value></value>
	</attr>
	<attr attr-name="u_kundenr">
		<value>1015425</value>
	</attr>
	<attr attr-name="sys_updated_on">
		<value>07.05.2019 04:47:12</value>
	</attr>
	<attr attr-name="apple_icon">
		<value></value>
	</attr>
	<attr attr-name="sys_updated_by">
		<value>BBC_POB</value>
	</attr>
	<attr attr-name="u_customer_alias">
		<value></value>
	</attr>
	<attr attr-name="fiscal_year">
		<value></value>
	</attr>
	<attr attr-name="sso_source">
		<value></value>
	</attr>
	<attr attr-name="sys_created_on">
		<value>06.10.2016 13:18:52</value>
	</attr>
	<attr attr-name="contact">
		<value></value>
	</attr>
	<attr attr-name="sys_domain">
		<value>{"display_value":"TOP/MSP/BBC","link":"http://servicenow-test.BBC.dk/api/now/table/domain/4c346138a44f12005821241c95d66248"}</value>
	</attr>
	<attr attr-name="u_problem_coordinator">
		<value>{"display_value":"PROBLEM","link":"http://servicenow-test.BBC.dk/api/now/table/sys_user_group/b4dab65fff02220028765dff7fa4adc7"}</value>
	</attr>
	<attr attr-name="stock_price">
		<value></value>
	</attr>
	<attr attr-name="banner_image">
		<value></value>
	</attr>
	<attr attr-name="state">
		<value></value>
	</attr>
	<attr attr-name="sys_created_by">
		<value>RestMQUser</value>
	</attr>
	<attr attr-name="longitude">
		<value></value>
	</attr>
	<attr attr-name="zip">
		<value>8500</value>
	</attr>
	<attr attr-name="profits">
		<value>kr 0,00</value>
	</attr>
	<attr attr-name="active">
		<value>true</value>
	</attr>
	<attr attr-name="sys_domain_path">
		<value>!!!/!!#/!!$/</value>
	</attr>
	<attr attr-name="fax_phone">
		<value></value>
	</attr>
	<attr attr-name="phone">
		<value>86326632</value>
	</attr>
	<attr attr-name="banner_text">
		<value></value>
	</attr>
	<attr attr-name="name">
		<value>Børnehaven Regnbuen</value>
	</attr>
	<attr attr-name="primary">
		<value>false</value>
	</attr>
	<attr attr-name="city">
		<value>Grenaa</value>
	</attr>
	<attr attr-name="latitude">
		<value></value>
	</attr>
	<attr attr-name="u_company_code">
		<value></value>
	</attr>
	<attr attr-name="sys_class_name">
		<value>Account</value>
	</attr>
	<attr attr-name="manufacturer">
		<value>false</value>
	</attr>
	<attr attr-name="sys_id">
		<value>00067ea5ff9a220072816dff7fa4ad17</value>
	</attr>
	<attr attr-name="market_cap">
		<value>kr 0,00</value>
	</attr>
	<attr attr-name="num_employees">
		<value></value>
	</attr>
	<attr attr-name="rank_tier">
		<value>null</value>
	</attr>
	<attr attr-name="street">
		<value>Lupinskrænten 6</value>
	</attr>
	<attr attr-name="vendor">
		<value>false</value>
	</attr>
	<attr attr-name="lat_long_error">
		<value></value>
	</attr>
	<attr attr-name="u_ssoidentifier">
		<value></value>
	</attr>
	<attr attr-name="vendor_type">
		<value></value>
	</attr>
	<attr attr-name="u_ean_number">
		<value></value>
	</attr>
	<attr attr-name="revenue_per_year">
		<value>kr 0,00</value>
	</attr>
	<attr attr-name="website">
		<value></value>
	</attr>
	<attr attr-name="publicly_traded">
		<value>false</value>
	</attr>
	<attr attr-name="sys_mod_count">
		<value>5</value>
	</attr>
	<attr attr-name="u_email_domain">
		<value></value>
	</attr>
	<attr attr-name="sys_tags">
		<value></value>
	</attr>
	<attr attr-name="vendor_manager">
		<value></value>
	</attr>
	<attr attr-name="customer">
		<value>false</value>
	</attr>
</instance>

 

0 Likes
sivaramtm Super Contributor.
Super Contributor.

Re: Help with parsing rest json response to XDS

Jump to solution

it worked for me as well. Thanks.

0 Likes
Highlighted
sivaramtm Super Contributor.
Super Contributor.

Re: Help with parsing rest json response to XDS

Jump to solution
Now i trying to synchronize couple of attributes from the response to IDV using filter and schema mapping but i dont see this works. Any thoughts?
0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Help with parsing rest json response to XDS

Jump to solution

You probably want to give the instance elements a class-name attribute.

0 Likes
sivaramtm Super Contributor.
Super Contributor.

Re: Help with parsing rest json response to XDS

Jump to solution

I have changed the schema mapping with out class now attributes are flowing furthur but the objects are not getting created due to below error.

<nds dtdversion="3.5" ndsversion="8.x">
<source>
<product build="20170130_0359" instance="Rest-ServicenowDW" version="1.0.0.1">Identity Manager REST Driver</product>
<contact>NetIQ Corporation.</contact>
</source>
<input>
<driver-operation-data class-name="" command="poll" event-id="Rest-ServicenowDW##1196118302##0">
<response>
{"result":[{"parent":"","total_cost":"kr 0,00","discount":"","cost_adjustment":"0","sys_updated_on":"06.12.2018 12:52:02","u_response_agreement":"","u_sapkontraktnr":"40069112","u_external_problems_allowed":"false","approval_history":"","number":"CNTR0374773","sub_total_cost":"kr 0,00","u_solution_architect":"","cost_adjustment_reason":"","state":"Active","sys_created_by":"RestMQUser","contract_composite":"40069112 - CNTR0374773 - 218199","yearly_cost":"kr 0,00","active":"true","payment_amount":"kr 0,00","u_language":"Danish","sys_domain_path":"!!!/!!#/!!$/","u_idm_2nd_level_approval":"false","terms_and_conditions":null,"u_problem_internal_priority":"5","cost_center":"","renewable":"true","contract_administrator":"","template":"","short_description":"Frederiksberg Forsyning A/S -","process_non_contractual_slas":"false","u_expected_resolution_email":"false","sys_class_name":"Contract","u_first_time_fix_allowed":"false","u_sdms":"","vendor":"","contract_model":"","u_contract_reference":"Purchase Agreement","approver":"","monthly_cost":"kr 0,00","license_type":null,"renewal_options":null,"substate":"Awaiting Review","application_model":"","u_problem_external_priority":"3","vendor_account":"","u_business_hours":"","cost_adjustment_percentage":"0","u_idm_2nd_level_approvers":"","renewal_end_date":"","tax_rate":"","tax_cost":"kr 0,00","sys_updated_by":"system","u_cab_approval_group":"","renewal_date":"","u_head_of_delivery":"","u_security_condition":"","sys_created_on":"06.10.2016 17:32:16","sys_domain":{"display_value":"TOP/MSP/BBC","link":"http://servicenow-test.BBC.dk/api/now/table/domain/4c346138a44f12005821241c95d66248"},"u_problem_coordinator":"","parent_contract":"","starts":"","tax_exempt":"false","commitment":"kr 0,00","payment_schedule":"Monthly","renewal_contact":"","expiration":"","invoice_payment_terms":null,"u_ci_access_group":"","u_department":"","u_send_survey_along_with_auto_resolve_mail":"false","ratecard":"false","cost_adjustment_type":null,"u_ci_visibility_usage_group":"","u_notes_ok_for_portal":"false","description":"","u_incident_priority":"3","u_reopen_time":"5","sys_id":"00007fadff5e220051b26dff7fa4ad59","po_number":"","license_quantity_entitled":"","u_approver":"","ends":"","consumer":"","process":null,"vendor_contract":"218199","lifetime_cost":"kr 0,00","sys_mod_count":"5","u_service_request_priority":"5","sys_tags":"","u_automatic_closure_mail_is_being_sent":"false","u_risk_assesment_group":"","u_head_of_business":"","sales_tax":"true","cost_per_unit":"kr 0,00","location":"","u_service_delivery_manager":"","account":"","u_delivery_manager":""}]}
</response>
</driver-operation-data>
</input>
</nds>

[07/11/19 08:30:02.386]:Rest-SN PT:Applying policy: %+C%14CNETQRESTJSON-itp-JSONtoXDS%-C.
[07/11/19 08:30:02.386]:Rest-SN PT: Applying to driver-operation-data #1.
[07/11/19 08:30:02.386]:Rest-SN PT: Evaluating selection criteria for rule 'Translate JSON to XDS'.
[07/11/19 08:30:02.386]:Rest-SN PT: (if-operation equal "driver-operation-data") = TRUE.
[07/11/19 08:30:02.386]:Rest-SN PT: (if-xpath true "string-length(response/value/text())>0") = TRUE.
[07/11/19 08:30:02.402]:Rest-SN PT: Rule selected.
[07/11/19 08:30:02.402]:Rest-SN PT: Applying rule 'Translate JSON to XDS'.
[07/11/19 08:30:02.402]:Rest-SN PT: Action: do-set-local-variable("lvResponse",scope="policy",arg-node-set(token-xpath("es:JSONtoXDS(response/value/text())"))).
[07/11/19 08:30:02.402]:Rest-SN PT: arg-node-set(token-xpath("es:JSONtoXDS(response/value/text())"))
[07/11/19 08:30:02.402]:Rest-SN PT: token-xpath("es:JSONtoXDS(response/value/text())")
[07/11/19 08:30:02.402]:Rest-SN PT: Token Value: { @level = "success" @type = "app-general", @SRC-dn = "undefined"}.
[07/11/19 08:30:02.402]:Rest-SN PT: Arg Value: { @level = "success" @type = "app-general", @SRC-dn = "undefined"}.
[07/11/19 08:30:02.402]:Rest-SN PT: Action: do-trace-message("My works.."+token-local-variable("lvResponse")).
[07/11/19 08:30:02.402]:Rest-SN PT: arg-string("My works.."+token-local-variable("lvResponse"))
[07/11/19 08:30:02.402]:Rest-SN PT: token-text("My works..")
[07/11/19 08:30:02.402]:Rest-SN PT: token-local-variable("lvResponse")
[07/11/19 08:30:02.402]:Rest-SN PT: Token Value: "number of responses: 1".
[07/11/19 08:30:02.402]:Rest-SN PT: Arg Value: "My works..number of responses: 1".
[07/11/19 08:30:02.402]:Rest-SN PT:My works..number of responses: 1
[07/11/19 08:30:02.402]:Rest-SN PT: Action: do-clone-xpath(dest-expression="..",src-expression="$lvResponse").
[07/11/19 08:30:02.402]:Rest-SN PT: Action: do-strip-xpath("$current-op").
[07/11/19 08:30:02.402]:Rest-SN PT: Evaluating selection criteria for rule 'ReadintoAttributes'.
[07/11/19 08:30:02.402]:Rest-SN PT: (if-xpath true "@level='success'") = FALSE.
[07/11/19 08:30:02.402]:Rest-SN PT: Rule rejected.
[07/11/19 08:30:02.402]:Rest-SN PT:Policy returned:
[07/11/19 08:30:02.402]:Rest-SN PT:


[07/10/19 15:26:44.292]:Rest-SN PT:Applying policy: %+C%14CNETQRESTDCFG-pub-ctp-ModifytoRename%-C.
[07/10/19 15:26:44.292]:Rest-SN PT: Applying to instance #1.
[07/10/19 15:26:44.292]:Rest-SN PT: Evaluating selection criteria for rule 'ReadintoAttributes'.
[07/10/19 15:26:44.292]:Rest-SN PT: (if-src-dn equal "undefined") = TRUE.
[07/10/19 15:26:44.292]:Rest-SN PT: Rule selected.
[07/10/19 15:26:44.292]:Rest-SN PT: Applying rule 'ReadintoAttributes'.
[07/10/19 15:26:44.292]:Rest-SN PT: Action: do-set-local-variable("lvnumber",scope="policy",token-attr("BBCSNContractNumber")).
[07/10/19 15:26:44.292]:Rest-SN PT: arg-string(token-attr("BBCSNContractNumber"))
[07/10/19 15:26:44.292]:Rest-SN PT: token-attr("BBCSNContractNumber")
[07/10/19 15:26:44.292]:Rest-SN PT: Token Value: "40069112 - CNTR0374773 - 218199".
[07/10/19 15:26:44.292]:Rest-SN PT: Arg Value: "40069112 - CNTR0374773 - 218199".
[07/10/19 15:26:44.292]:Rest-SN PT: Action: do-set-local-variable("dn",scope="policy","BBC\Servicenow\Contract"+"\"+token-attr("CN")).
[07/10/19 15:26:44.292]:Rest-SN PT: arg-string("BBC\Servicenow\Contract"+"\"+token-attr("CN"))
[07/10/19 15:26:44.292]:Rest-SN PT: token-text("BBC\Servicenow\Contract")
[07/10/19 15:26:44.292]:Rest-SN PT: token-text("\")
[07/10/19 15:26:44.292]:Rest-SN PT: token-attr("CN")
[07/10/19 15:26:44.292]:Rest-SN PT: Token Value: "CNTR0374773".
[07/10/19 15:26:44.292]:Rest-SN PT: Arg Value: "BBC\Servicenow\Contract\CNTR0374773".
[07/10/19 15:26:44.292]:Rest-SN PT: Action: do-set-op-dest-dn(arg-dn(token-local-variable("dn"))).
[07/10/19 15:26:44.292]:Rest-SN PT: arg-dn(token-local-variable("dn"))
[07/10/19 15:26:44.307]:Rest-SN PT: token-local-variable("dn")
[07/10/19 15:26:44.307]:Rest-SN PT: Token Value: "BBC\Servicenow\Contract\CNTR0374773".
[07/10/19 15:26:44.307]:Rest-SN PT: Arg Value: "BBC\Servicenow\Contract\CNTR0374773".
[07/10/19 15:26:44.307]:Rest-SN PT: Action: do-trace-message("New Contract created..").
[07/10/19 15:26:44.307]:Rest-SN PT: arg-string("New Contract created..")
[07/10/19 15:26:44.307]:Rest-SN PT: token-text("New Contract created..")
[07/10/19 15:26:44.307]:Rest-SN PT: Arg Value: "New Contract created..".
[07/10/19 15:26:44.307]:Rest-SN PT:New Contract created..
[07/10/19 15:26:44.307]:Rest-SN PT: Evaluating selection criteria for rule 'Convert modify to rename'.
[07/10/19 15:26:44.307]:Rest-SN PT: (if-operation equal "modify") = FALSE.
[07/10/19 15:26:44.307]:Rest-SN PT: Rule rejected.
[07/10/19 15:26:44.307]:Rest-SN PT:Policy returned:
[07/10/19 15:26:44.307]:Rest-SN PT:
<nds dtdversion="3.5" ndsversion="8.x">
<source>
<product build="20170130_0359" instance="Rest-ServicenowDW" version="1.0.0.1">Identity Manager REST Driver</product>
<contact>NetIQ Corporation.</contact>
</source>
<input>
<instance dest-dn="BBC\Servicenow\Contract\CNTR0374773" src-dn="undefined">
<attr attr-name="parent">
<value></value>
</attr>
<attr attr-name="total_cost">
<value>kr 0,00</value>
</attr>
<attr attr-name="discount">
<value></value>
</attr>
<attr attr-name="cost_adjustment">
<value>0</value>
</attr>
<attr attr-name="sys_updated_on">
06.12.2018 12:52:02
</attr>
<attr attr-name="u_response_agreement">
<value></value>
</attr>
<attr attr-name="u_sapkontraktnr">
<value>40069112</value>
</attr>
<attr attr-name="u_external_problems_allowed">
<value>false</value>
</attr>
<attr attr-name="approval_history">
<value></value>
</attr>
<attr attr-name="CN">
<value>CNTR0374773</value>
</attr>
<attr attr-name="sub_total_cost">
<value>kr 0,00</value>
</attr>
<attr attr-name="u_solution_architect">
<value></value>
</attr>
<attr attr-name="cost_adjustment_reason">
<value></value>
</attr>
<attr attr-name="state">
<value>Active</value>
</attr>
<attr attr-name="sys_created_by">
<value>RestMQUser</value>
</attr>
<attr attr-name="BBCSNContractNumber">
<value>40069112 - CNTR0374773 - 218199</value>
</attr>
<attr attr-name="yearly_cost">
<value>kr 0,00</value>
</attr>
<attr attr-name="active">
<value>true</value>
</attr>
<attr attr-name="payment_amount">
<value>kr 0,00</value>
</attr>
<attr attr-name="u_language">
<value>Danish</value>
</attr>
<attr attr-name="sys_domain_path">
<value>!!!/!!#/!!$/</value>
</attr>
<attr attr-name="u_idm_2nd_level_approval">
<value>false</value>
</attr>
<attr attr-name="terms_and_conditions">
<value>null</value>
</attr>
<attr attr-name="u_problem_internal_priority">
<value>5</value>
</attr>
<attr attr-name="cost_center">
<value></value>
</attr>
<attr attr-name="renewable">
<value>true</value>
</attr>
<attr attr-name="contract_administrator">
<value></value>
</attr>
<attr attr-name="template">
<value></value>
</attr>
<attr attr-name="short_description">
<value>Frederiksberg Forsyning A/S -</value>
</attr>
<attr attr-name="process_non_contractual_slas">
<value>false</value>
</attr>
<attr attr-name="u_expected_resolution_email">
<value>false</value>
</attr>
<attr attr-name="sys_class_name">
<value>Contract</value>
</attr>
<attr attr-name="u_first_time_fix_allowed">
<value>false</value>
</attr>
<attr attr-name="u_sdms">
<value></value>
</attr>
<attr attr-name="vendor">
<value></value>
</attr>
<attr attr-name="contract_model">
<value></value>
</attr>
<attr attr-name="u_contract_reference">
<value>Purchase Agreement</value>
</attr>
<attr attr-name="approver">
<value></value>
</attr>
<attr attr-name="monthly_cost">
<value>kr 0,00</value>
</attr>
<attr attr-name="license_type">
<value>null</value>
</attr>
<attr attr-name="renewal_options">
<value>null</value>
</attr>
<attr attr-name="substate">
<value>Awaiting Review</value>
</attr>
<attr attr-name="application_model">
<value></value>
</attr>
<attr attr-name="u_problem_external_priority">
<value>3</value>
</attr>
<attr attr-name="vendor_account">
<value></value>
</attr>
<attr attr-name="u_business_hours">
<value></value>
</attr>
<attr attr-name="cost_adjustment_percentage">
<value>0</value>
</attr>
<attr attr-name="u_idm_2nd_level_approvers">
<value></value>
</attr>
<attr attr-name="renewal_end_date">
<value></value>
</attr>
<attr attr-name="tax_rate">
<value></value>
</attr>
<attr attr-name="tax_cost">
<value>kr 0,00</value>
</attr>
<attr attr-name="sys_updated_by">
<value>system</value>
</attr>
<attr attr-name="u_cab_approval_group">
<value></value>
</attr>
<attr attr-name="renewal_date">
<value></value>
</attr>
<attr attr-name="u_head_of_delivery">
<value></value>
</attr>
<attr attr-name="u_security_condition">
<value></value>
</attr>
<attr attr-name="sys_created_on">
06.10.2016 17:32:16
</attr>
<attr attr-name="sys_domain">
{"display_value":"TOP/MSP/BBC","link":"http://servicenow-test.BBC.dk/api/now/table/domain/4c346138a44f12005821241c95d66248"}>
</attr>
<attr attr-name="u_problem_coordinator">
<value></value>
</attr>
<attr attr-name="parent_contract">
<value></value>
</attr>
<attr attr-name="starts">
<value></value>
</attr>
<attr attr-name="tax_exempt">
<value>false</value>
</attr>
<attr attr-name="commitment">
<value>kr 0,00</value>
</attr>
<attr attr-name="payment_sch...
























































































































Knowledge Partner
Knowledge Partner

Re: Help with parsing rest json response to XDS

Jump to solution

You send an event in XDS. 

nds, then input or output. 

Under input should be add, modify, delete, rename, move, and some more.

But instance is a response, so it should be under an output node.

So I assume you built the XDS/XML in policy somewhere to convert the REST response to an <instance> so go fix it.

 

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.