Is there a way to query the ECC queue payload and get a value from it?

Ajai S Nair
Giga Guru

Hi All,

For one of my automation item I need to query some table from a SAP system and evaluate some value of a field. Now I got a sample script from concerned team for this. But after querying it will echo the value. If so can we get that value from ECC queue payload based on the variable inside it ?

6 REPLIES 6

tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Ajai,



You can query the ECC queue like so:


Using GlideRecord to Query Tables - ServiceNow Wiki



Perhaps you could grab the payload along the lines of the (untested) code below and then proceed to parse the payload?


var rec = new GlideRecord('ecc_queue'); 
rec.addQuery("response_to", outputSysId);
rec.addQuery("queue", "input");
while (rec.next())
{
gs.print(rec.payload);
}

Best Regards



Tony


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Ajai,



If I understand well your request, you want to parse the XML payload from records in ECC queue based on a particular tag and get the value out of it?


If that's the case ServiceNow has already a script include to parse XML: "XMLDocument" and it's documented here:



XMLDocument Script Object - ServiceNow Wiki



Another way of doing it is via javascript function match, but it might be slower than ServiceNow XMLDocument script include. Here is a quick example of getting the value of sys_created_on and using it after:



var gr = new GlideRecord('ecc_queue');      


gr.addQuery("queue", "input");


gr.query();



while(gr.next()) {


          var text = gr.payload;


          match = text.match(/<sys_created_on>([^<]*)<\/sys_created_on>/);


            result = match[1];


            gs.log(result);


            if (result >= '2015-09-21 23:59:59'){


                      // do something


        }


}




Regards,


Sergiu


Thanks Tony and Sergui for the reply. I will try this for my requirement.


Hi Ajai,



Thanks for your update.


It might be worth mentioning that you can explore the contents of the ECC Queue using a list view and identify payloads you are interested in, by applying filters.


Navigate to ECC > Queue and create a filter condition containing any on the ECC queue fields, Agent, Topic, Source or Queue (Input or Output).



Any filter created in the list view, can be reused in a glide record query against the ecc_queue table.



Along the lines of:


var rec = new GlideREcord('ecc_queue');


rec.addEncodedQuery('sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)^queue=input^topicLIKESAP');


rec.query();


while (rec.next())


{    


      gs.print(rec.payload);    


//your code here


}




Best Regards



Tony