Posts

Showing posts from September, 2021

Script a web service call into a data source

Image
 see https://docs.servicenow.com/bundle/rome-platform-administration/page/administer/import-sets/reference/custom-type-data-source.html data loader script: ( function loadData ( import_set_table ) { //--https://docs.servicenow.com/bundle/rome-platform-administration/page/administer/import-sets/reference/custom-type-data-source.html var si = new test_outbound (); //--call a web service via script include var resp = si . testUser_singleUser (); //gs.log('RESPONSE=' + resp); var obj = JSON . parse ( resp ); gs . log ( 'ID=' + obj . result . id ); //--do this the first time round to create the columns /*import_set_table.addColumn('id', obj.result.id); import_set_table.addColumn('email', obj.result.email); import_set_table.addColumn('firstname', obj.result.known_as); import_set_table.addColumn('lastname', obj.result.surname);*/ var map = {}; map [ 'id' ] = obj

REST Testharness

Image
 Scripted REST endpoint: this is a simple example using a script include to return a hard-coded JSON string ( function process ( /*RESTAPIRequest*/ request , /*RESTAPIResponse*/ response ) { //--build up a test response var sRestRespStr = new testResponse_singleUser (); return sRestRespStr ; })( request , response ); (sample JSON: { "id" : "yyyyy-zzzz-12323-1256-xxxxx" , "known_as" : "Daniel" , "surname" : "Smith" , "email" : "test@test.net" } )  REST message: a message calling the above endpoint. Here is it's HTTP Method example script for the REST Message - the parameters are the REST Message and the HTTP Method (these can be named differently) testUser_singleUser : function () { try { var r = new sn_ws . RESTMessageV2 ( ' test ' , ' test ' ); var resp = r . execute ();

ServiceNow View Rules

view rules

Debug best practice

 https://developer.servicenow.com/dev.do#!/guides/orlando/now-platform/tpb-guide/debugging_best_practices

Check that the current record is a certain table

 business rule runs on the interaction table // This BR will only run for Incidents, so get the Sys ID and check that the record being inserted is an Incident var sDocId = current . getValue ( 'document_id' ) || "" ; var grIncident = new GlideRecord ( 'incident' ); if ( grIncident . get ( sDocId )) {

Copy a virtual agent chat transcript to the incident via agent workspace

Image
 business rule will: - add the transcript to the incident worknotes - attach the transcript as a text file to the incident  script : ( function executeRule ( current , previous /*null when async*/ ) { // This BR will only run for Incidents, so get the Sys ID and check that the record being inserted is an Incident var sDocId = current . getValue ( 'document_id' ) || "" ; var grIncident = new GlideRecord ( 'incident' ); if ( grIncident . get ( sDocId )) { // We have an Incident, so let's get the respective interaction record var sTranscript = current . interaction . transcript ; var sTranscriptHeader = gs . getMessage ( "moj.interaction.transcript_header" ); // Update the related Incident grIncident . work_notes = sTranscriptHeader + "\n\n" + sTranscript ; grIncident . update (); // Add chat transcript as

ServiceNow and Atlassian/Jira: tokens

 Using Personal Access Tokens | Atlassian Support | Atlassian Documentation https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html

Code a 'cancel and copy to new change type' ui action

 typical usage: - the change is at change manager approval stage, and the change manager wishes to reject the change due to the wrong change type having been selected. The original change will be cancelled, and the fields copied to a new change. As part of the copy the user will be presented with a dialog to select the new change via UI Action UI Action code: condition:  gs . hasRole ( 'change_manager' ) && ( gs . getUser (). isMemberOf ( 'Change Management' ) || gs . hasRole ( 'admin' ) ) && ChangeUtils . isCopyChangeEnabled ( current ) script: function confirmAction () { var gmConfirm = new GlideModal ( 'confirm_change_cancel_copy' ); gmConfirm . setTitle ( 'Confirm your cancellation!' ); gmConfirm . setPreference ( 'title' , getMessage ( 'chg.cancel_copy_warning_msg' )); gmConfirm . setPreference ( 'warning' , 'true' ); gmConfirm . setPreference ( 'on