Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Kalaiarasan Pus
Giga Sage

There are many hidden gems in ServiceNow which are undocumented for some reason or the other. One such thing is a interesting function that I found while looking into the script include 'StdChangeUtilsSNC', called applyEncodedQuery() of GlideRecord.

 

Let's just say you have a use case where you have a encoded query and want to create or update a record using it. Here comes applyEncodedQuery() to your rescue. Below is a quick sample on how you can use the function.

 

var filter = 'caller_id=javascript:gs.getUserID()^active=true^short_description=Test^state=2';
var records = new GlideRecord('incident');
records.initialize();
records.applyEncodedQuery(filter);
records.insert();

 

The above code creates a incident with caller, short description and state being 'In Progress'.

Note: Tested the function in global scope.

 

If you liked the content, please share, click helpful, bookmark or leave your valuable comments.

7 Comments