How to call Server API within a pattern?

PN5
Mega Contributor

I have to do a gliderecord query to get data in one of the patterns. I have tried 'Set Parameter Value' with eval of the below javscript(formatted with \n here for better readability). GlideRecord does not seem to get processed, control always hits the else loop. The encoded query gives results when tried in UI so there is no issue with that. Same script works when I run it in background. Is there a package to be included to make GLideRecord work ?

 

javascript:
var rtrn = '';
var query = 'computer.name='+${computer_system.primaryHostname}+'^pid='+${process.pid};var gr = new GlideRecord('sometable');
gr.addEncodedQuery(query);
gr.query();
if(gr.next()){ rtrn = gr.port;}
else rtrn = '0';
rtrn;
4 REPLIES 4

Phillip Le Roy
ServiceNow Employee
ServiceNow Employee

Hi PN,

I believe the best option is to create a Custom Operation and put your script there. And then create a step from your Pattern using this custom Operation.

Would that work for your scenario?

See more details about creating Custom Operations here:

https://docs.servicenow.com/bundle/kingston-it-operations-management/page/product/service-mapping/ta...

 

Regards,

Phillip

Hey man, Custom Operations are really the way to go, however the Custom Operation step requires me to return a String and then choose a parsing strategy. What if I want a Custom Operation that just takes a table and returns a table, with no parsing needed?

PN5
Mega Contributor

Hey Phillip , thank you for the link on custom operations. However I found out that the reason the API call failed in my pattern was because of the ACL on the table. The pattern I believe makes a REST call behind the scenes and it was using a user that did not have access on that table.

 

PN:

Thanks!  This approach cracked a big problem I was having in my Discovery Horizontal Pattern.  It gave me the clue I needed to solve the issue.

Steven.