Skip to main content

Posts

Showing posts from June, 2023

ServiceNow Arrays: check array contains a value

 ServiceNow Arrays: check array contains a value flat_file_arr.indexOf(emplNum, 0)>-1 ; //--t-map on complete script accountTableTrueUp ( import_set . number ); //accountTableTrueUp('ISET0011535'); function accountTableTrueUp ( import_set_number ) { var flat_file_arr = []; var grST = new GlideRecord ( 'x_cls_clear_skye_i_eon_hr_import' ); //--the staging table name of the transform grST . addEncodedQuery ( 'sys_import_set.number=' + import_set_number ); grST . query (); while ( grST . next ()) { flat_file_arr . push ( grST . u_employeenumber + '' ); } var grAC = new GlideRecord ( 'x_cls_clear_skye_i_account' ); grAC . addEncodedQuery ( 'account_type=5bd21b7b97db2550df843a300153af71^status=1' ); grAC . query (); while ( grAC . next ()) { var emplNum = grAC . getValue ( 'employee_number' ); var bMa...

ServiceNow Transform Maps: check if all rows in the import staging table match the target rows

 ServiceNow Transform Maps: check if all rows in the import staging table match the target rows //--t-map on complete script accountTableTrueUp ( import_set . number ); //accountTableTrueUp('ISET0011535'); function accountTableTrueUp ( import_set_number ) { var flat_file_arr = []; var grST = new GlideRecord ( 'x_cls_clear_skye_i_eon_hr_import' ); //--the staging table name of the transform grST . addEncodedQuery ( 'sys_import_set.number=' + import_set_number ); grST . query (); while ( grST . next ()) { //gs.print('employee number:' + grST.u_employeenumber); //flat_file_arr.push(grST.sys_target_sys_id+''); flat_file_arr . push ( grST . u_employeenumber + '' ); } gs . print ( 'flat_file_arr=' + flat_file_arr . toString ()); var arrStr = flat_file_arr . toString (); var grAC = new GlideRecord ( 'x_cls_clear_...

ServiceNow Accessing the import_set api in a Transform Map Script

ServiceNow Accessing the import_set api in a Transform Map Script  link:  https://developer.servicenow.com/dev.do#!/reference/api/utah/rest/c_ImportSetAPI how you could loop through target records in an onComplete t-map script: (Change the staging table name to your import set table, or alternatively use sys_import_set) var grST = new GlideRecord ( 'x_cls_clear_skye_i_eon_hr_import' ); grST . addEncodedQuery ( 'sys_import_set.number=' + import_set . number ); grST . query (); while ( grST . next ()) { gs . warn ( 'row--' + grST . sys_target_sys_id ); }

ServiceNow Random String Generator (Javascript)

ServiceNow Random String Generator (Javascript) credit gs . print ( makeid ( 4 )); function makeid ( length ) { var result = '' ; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ; var charactersLength = characters . length ; var counter = 0 ; while ( counter < length ) { result += characters . charAt ( Math . floor ( Math . random () * charactersLength )); counter += 1 ; } return result ; }

ServiceNow Transform Map - prevent a particular row from being processed

 ServiceNow Transform Map - prevent a particular row from being processed example 'run script' code ( function transformRow ( source , target , map , log , isUpdate ) { if ( action == 'insert' && source . u_status == 'I' ){ gs . warn ( source . u_employeenumber + ' row ignored-disable on insert is not required::T-MAP' ); ignore = true ; } })( source , target , map , log , action === "update" );

ServiceNow Neat Little Trick for Quickly Grabbing a Breadcrumb Query (SNUtils)

 ServiceNow Neat Little Trick for Quickly Grabbing a Breadcrumb Query (SNUtils) for copy paste purposes I've noticed by double clicking the breadcrumb the query comes up in a box, pretty cool (note am currently on a Mac so left double clicking) hey presto...box appears! see my other posts on SNUtils

ServiceNow orderBy and orderByDesc

 ServiceNow orderBy and orderByDesc by default, orderBy orders by ascending to order by descending , use orderByDesc see  https://developer.servicenow.com/dev.do#!/reference/api/utah/server/no-namespace/c_GlideRecordScopedAPI#r_ScopedGlideRecordOrderBy_String

ServiceNow chars in string - date field from source HR system

ServiceNow chars in string - date field from source HR system where source date format: 20140201000000Z var sStartDateImp = '20140201000000Z' ; var sSD_trunc_y = sStartDateImp . substring ( 0 , 4 ); var sSD_trunc_m = sStartDateImp . charAt ( 4 )+ sStartDateImp . charAt ( 5 ); var sSD_trunc_d = sStartDateImp . charAt ( 6 )+ sStartDateImp . charAt ( 7 ); gs . print ( sSD_trunc_y + '-' + sSD_trunc_m + '-' + sSD_trunc_d );   *** Script: 2014-02-01

ServiceNow use a variable in a transform script

 ServiceNow use a variable in a transform script onStart transform script: var environmentID = 'cf38f56397d7a150df843a300153af0a' ; field mapping: return environmentID + source.u_employeenumber; Note : if for some reason it doesn't work, comment out the function lines in the transform script like so: //(function runTransformScript(source, map, log, target /*undefined onStart*/ ) { var environmentID = ' cf38f56397d7a150df843a300153af0a ' ; //})(source, map, log, target);

ServiceNow how to export the audit history of a record

ServiceNow how to export the audit history of a record see also my post on how to retrieve by url using record sys_id:  Use the set column and drop the sys_id of the record in there, it should refresh to display the number:

ServiceNow ConversionError: The undefined value has no properties

 ServiceNow ConversionError: The undefined value has no properties see  https://www.servicenow.com/community/developer-forum/error-while-calling-script-include-from-client-script/m-p/2172821 If you are not extending GlideAjax, you need to initialize the class before defining the methods. Since you need it to be client-callable, you need to extend GlideAjax class.

ServiceNow Service Catalog Advanced Reference Qualifier in SCOPED app -CHALLENGES (List Collector)

 ServiceNow Service Catalog Advanced Reference Qualifier in SCOPED app -CHALLENGES (List Collector) in the list collector reference qualifier I am passing the value of a reference variable to the script include I found it necessary to  pass it in this format using toString () use the fully qualified api name (including the api scope, in this case   x_cls_clear_skye_i do not use  ref_qual_elements  in the variable attributes box seems necessary to click the 'run filter' button on the list collector to pull back the results in order for it to work: javascript:new x_cls_clear_skye_i .myScriptInclude().testFunction(current.variables.account. toString ()); script include example function: testFunction : function ( sAccount ) { gs . warn ( 'test::ClearSkyeTableServerSide.testFunction-sAcc=' + sAccount ); //gs.warn('test::ClearSkyeTableServerSide.testFunction-'); return ( 'sys_id=d1e1c87e9769ad10df843a300153af45' ); } seem...

ServiceNow Scoped App Logging

 ServiceNow Scoped App Logging (search terms: ServiceNow Scoped Application Logging ServiceNow Scoped Application Logs ) see also setting the log destination and  https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0752278 gs.warn and gs.error will show up in the application logs to enable gs.info and gs.debug, Go to the sys_app table (e.g. type sys_app.list in the Application navigator search box), find your scoped app record in the list and open it. Down in the Related links, you'll see "enable session debugging" - click it. To debug the Condition field script, enable detailed Business Rule Debugging. Use the Application Navigator to open  System Diagnostics >Session Debug > Debug Business Rules (Details) . This module turns on logging of debug information to forms and lists. Open the form for a record of interest and force the Business Rule you are debugging to execute by doing whatever is necessary to trigger the Business Rule. Log level |...

ServiceNow Service Catalog Advanced Reference Qualifier in SCOPED app

ServiceNow Service Catalog Advanced Reference Qualifier in SCOPED app observations: the script include is created within the scoped app but needs to be accessible from all scopes client callable box does not need to be ticked example calling from the ref qual field on the catalog variable ( lookup select box ): javascript:'sys_idIN' + new x_cls_clear_skye_i.ClearSkyeTableServerSide().retrieveMemberships(current.variables.account) example calling from the ref qual field on the catalog variable ( list collector ): javascript:'sys_idIN'+new x_cls_clear_skye_i.ClearSkyeTableServerSide().retrieveMemberships(current.variables.account.toString()) note the 'variable attributes' field on the variable: ref_auto_completer=AJAXTableCompleter,ref_ac_columns=group (my observation is that ref_qual_elements =account causes the filter to BREAK!! So leave it out s. ee  https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0746780 also, it does not appear to b...

ServiceNow select a user role on this client callable script include message

ServiceNow select a user role on this client callable script include see  https://www.servicenow.com/community/now-platform-articles/privacy-on-client-callable-script-includes-instance-security/ta-p/2386648 https://docs.servicenow.com/bundle/vancouver-platform-security/page/administer/security/reference/privacy-on-client-callable-script-includes.html f needed, you can change the privacy setting for an individual client-callable script include by adding the  isPublic()  function. The  isPublic()  setting takes precedence over the  glide.script.ccsi.ispublic property . For example, if you set  isPublic()  to true in an individual script, it makes it public, which overrides the  glide.script.ccsi.ispublic  property that makes all other client-callable script includes private isPublic:function(){return[true/false];}, https://docs.servicenow.com/bundle/utah-platform-security/page/administer/security/reference/privacy-on-client-callable-script...

ServiceNow Grab Detailed Logs

ServiceNow Grab Detailed Logs go to: https://<instance_name>.service-now.com /ui_page_process.do?name=log_file_browser and specify a time range, e.g.  results: you can also specify message content or thread name for example: see also:  https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0958075