Skip to main content

Posts

Exporting Sysids to a spreadsheet (CSV web service)

Exporting Sysids to a spreadsheet (CSV web service) really useful post on how to get sysids added as a column to a CSV export (CSV web service) https://developer.servicenow.com/blog.do?p=/post/exporting-data-with-sys-ids/ in a nutshell: - edit the system property SYSPARM_DEFAULT_EXPORT_FIELDS to add in the sys id column, or just add as a parameter to the URL like so: https://instance.service-now.com/incident_list.do?CSV& sysparm_default_export_fields=all - fire the URL at the instance, e.g. 'active tickets where vendor = <a vendor>', examples: https://instance.service-now.com/incident.do?CSV&sysparm_query=priority=1^active=true https://instance.service-now.com/incident.do?CSV& sysparm_default_export_fields=all &sysparm_query=priority=1^active=true https://instance.service-now.com/incident.do?CSV&CSV&sysparm_default_export_fields=all&sysparm_query=active=true^u_vendor=91c6f451371e420041c5616043990eee t his format seems to work ...

REST attachment

var sys_attach_gr = new GlideRecord ( 'sys_attachment' ); if ( sys_attach_gr . get ( 'sys_id' , 'fb2890fddbef0700f60fe2e15b9619c9' )){   var attachmentMessage = new sn_ws . RESTMessageV2 ();   attachmentMessage . setHttpMethod ( "post" );   attachmentMessage . setBasicAuth ( 'smithr' , 'Beethoven1' );   attachmentMessage . setEndpoint ( " https://mitchellsbutlersdev.service-now.com/api/now/attachment/file " );   attachmentMessage . setQueryParameter ( "table_name" , "incident" );   attachmentMessage . setQueryParameter ( "table_sys_id" , "2f96bf2637230f408ca1138943990e2a" );   attachmentMessage . setQueryParameter ( "file_name" , sys_attach_gr . file_name );   attachmentMessage . setRequestHeader ( "Content-Type" , sys_attach_gr . content_type );   attachmentMessage . setRequestHeader ( "Accept" , "application/json...

GlideAggregate: incidents by category

var ga = new GlideAggregate ( 'incident' ); ga . addAggregate ( 'COUNT' , 'category' ); //ga.addActiveQuery(); ga . setGroup ( true ); ga . groupBy ( "category" ); ga . query (); while ( ga . next ()) {   gs . info ( 'Category ' + ga . category + ' ' + ga . getAggregate ( 'COUNT' , 'category' )); }

ServiceNow Is value in array?

ServiceNow Is value in array? //--RDS Jan2018 //--monthly job to remove group memberships & roles from users in ServiceNow //--where user.active=false //--hence, licence tidy up task so that reporting reflects more accurate license allocation beforeChecks ( '' ); beforeChecks ( 'active=true' ); beforeChecks ( 'active=false' ); //gs.print('set bDelete=true to run the actual deletions, otherwise safe to run this script to spit out the numbers only'); var logSource = 'schJob:RolesTidyUp' ; var grUserRoles = new GlideRecord ( 'sys_user_has_role' ); grUserRoles . addQuery ( 'user.active=false' ); grUserRoles . orderBy ( 'user' ); grUserRoles . query (); var rowCount = grUserRoles . getRowCount (); gs . log ( 'START:: rowcount of inactive user> user roles in ServiceNow: ' + rowCount , logSource ); if ( rowCount > 0 ){     var userArr =[];     while ( grUserRoles . ...