Posts

Showing posts from June, 2018

Transform maps: store an error value in a session object, to pass from one transform map to another

transform map 1 : we want to flag an issue to pass to transform map 2, which has its order set to a higher order so it runs after transform 1 (both fire off the same import set) var session = gs . getSession (); var sSessionErr = 'no_errors' ; if ( bIgnore ){ / /set higher up in the script somewhere to flag an issue     sSessionErr = 'an error -- text' ;     response . error_string_inc = sSessionErr ; //--if stuck in the old world of SOAP as opposed rest, can alter the response [web service transform maps only]...     gs . log ( sSessionErr , 'inc_transf_1' );     ignore = true ; //this transform will ignore } session . putClientData ( ' tmap_xyz_Errs ' , sSessionErr ); transform map 2 : grab the error session string and alter the logic if it's present: var incTransfErrs = session . getClientData ( ' tmap_xyz_Errs ' ); if ( incTransfErrs == 'no_errors' ){         response . mab_error_string_t

ServiceNow PERSPECTIUM: outbound table maps> field maps> field types

When the outbound table map will result in an XML, may as well define all field types (even if the source/target field is Boolean for example) as String

ServiceNow PERSPECTIUM: how to map attachments in an outbound table map field mapping

Image
//--this goes in source field: //--${TM:psp_attachment;table_sys_id=$[GR:sys_id];msp_client_incident_sent;skip_insert}

ServiceNow PERSPECTIUM: how to return the target ticket number when the source system inserts a ticket

transform map: onAfter script //--return the MAB number to TSFNow ( function runTransformScript ( source , map , log , target /*undefined onStart*/ ) {         var logSource = ':TMAP:AFTER-SRIPT:INC' ;     var logPrefix = ' [ number: ' + source . u_number + ';   number' + source . u_correlation_display + '] ' ;         if ( action == 'update' && target . u_vendor == '91c6f451371e420041c5616043990eee' ){         if ( target . state == 6 && target . u_vendor_reference_number == '' ){ //--Fujitsu             //--update the vendor ref number             //-- ......             var grInc = new GlideRecord ( 'incident' );             if ( grInc . get ( 'number' , source . u_number )){                 grInc . u_vendor_reference_number = source . u_correlation_display ;                 grInc . update ();             }         }     }         i

ServiceNow PERSPECTIUM: how to map an attachment file in the inbound transform map

onAfter script: INCIDENT EXAMPLE: //--Attachments handling: ( function runTransformScript ( source , map , log , target /*undefined onStart*/ ) {     //gs.log('--test attach');         if ( source . u_attachments . nil ()){         return ; // noop     } else {         //gs.log('--test attach 2');         var pspAtt = new PerspectiumAttachment ();                 var xmldoc = new XMLDocument ( source . u_attachments );         var nodelist = xmldoc . getNodes ( "//attachment" );         if ( nodelist == null ){             return ; // noop         }         for ( var ii = 0 ; ii < nodelist . getLength (); ii ++) {             var nodeItem = nodelist . item ( ii );             pspAtt . addAttachment ( nodeItem , "incident" , target . sys_id , "msp_client_incident_sent" );         }     } })( source , map , log , target ); ----------------------------------------

ServiceNow PERSPECTIUM: how to map either the last worknotes or the full history, depending on whether insert or update

Image
//in the outbound table map, field mapping: answer = getWNList (); function getWNList (){     var sReturn = current . work_notes . getJournalEntry ( 1 );     gs . log ( current . number + ': OP=' + , 'getWNList' );     if ( current . operation ()== 'insert' ){         sReturn = current . work_notes . getJournalEntry (- 1 );     }     return sReturn ; }