Showing posts with label ServiceNow. Show all posts
Showing posts with label ServiceNow. Show all posts

Wednesday, 28 May 2025

ServiceNow bash export XML

 ServiceNow import limit 1G

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0564441&utm_source=chatgpt.com

but close or less than limit might still break system


export xml limit

https://www.servicenow.com/docs/bundle/yokohama-platform-administration/page/administer/exporting-data/concept/c_ExportLimits.html


A warning threshold property called glide.ui.export.warn.threshold controls how the records are exported. When you export enough records from a list to exceed the threshold, a choice dialog appears. You can choose to wait for the export to complete or email the exported records as an attachment. The warning threshold can be changed in the system property. The email attachment must not exceed the maximum Email size limits.

For export XML UI:

For XML go to UI use filter created at or after xxx date -> export xml

KB

break record into chunks

https://www.servicenow.com/docs/bundle/yokohama-platform-administration/page/administer/exporting-data/task/t_BreakUpALargeExport.html

If the record number is higher than the defined threshold, issue a sysparm query for the first 10,000 records using the following syntax:

Explain this code

https://<instance name>.service-now.com/syslog_list.do?XML&sysparm_orderby=sys_id&sysparm_record_count=10000


Access the next series of records with a greater than or equal to query run against the sys_id of record 10,001.

The following example shows a query that uses a sys_id of b4aedb520a0a0b1001af10e278657d27. Use the syntax shown in this query to export the next set of records.

https://<instance name>.service-now.com/syslog_list.do?XML&sysparm_query=sys_id%3E%3Db4aedb520a0a0b1001af10e278657d27&sysparm_orderby=sys_id&sysparm_record_count=10000

Saturday, 18 January 2025

ServiceNow OAUTH

 ServiceNOW OAUTH using JWT and HS256

https://www.servicenow.com/docs/bundle/washingtondc-platform-security/page/administer/security/task/create-jwt-endpoint.html

https://jwt.io/


It does support other parties OAUTH algorthim

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0859843



ServiceNow OAUTH obtain also need username and password(token will grant the permission of the user to access the API)

https://www.servicenow.com/community/developer-forum/oauth2-0-without-username-and-password/m-p/1470323


  1. Endpoint - https://instanceName.service-now.com/oauth_token.do

Method - POST


Request Body Key values



Key


Value


grant_type


password


client_id


your client id


client_secret


your client secret


username


username with rest role


password


password for that user


Wednesday, 17 July 2024

ServiceNow restrict user login based on IP && IP address control && installtion exists

 1)

global level :

https://docs.servicenow.com/bundle/washingtondc-platform-security/page/administer/login/task/t_AccessControl.html

IP address control configs


2) 

Indvidual level:

https://docs.servicenow.com/bundle/washingtondc-platform-security/page/script/server-scripting/reference/r_InstallationExits.html

https://www.servicenow.com/community/itsm-blog/if-multi-sso-is-installed-check-saml-installations-exits-are/ba-p/2268232

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743808

installation exists:

local user: login.js

MUTI SSO: 

MultiSSOv2.js

*/

    process : function() {

var clientIP = gs.getSession().getClientIP().toString();

            return "failed_authentication";


lets encrypt (Free) vs other paid ca

 lets encrypt(free) vs digi cert(paid)


https://www.quora.com/When-Lets-Encrypt-is-freely-available-why-do-companies-still-use-Digicert-and-other-paid-certificate-authorities


Extended Validation (EV) Certificates: Paid certificate authorities offer EV certificates which provide additional validation of the organization's identity and can help establish trust with visitors.

Warranty: Some paid certificate authorities offer warranties that protect against financial loss in the event of a security breach.

Support: Paid certificate authorities often provide dedicated support to help organizations through the certificate issuance and installation process.

Compatibility: Some older devices or browsers may not support Let's Encrypt certificates, so companies may choose to use a paid certificate authority to ensure compatibility with all devices and browsers.

Brand Recognition: Some companies may prefer to use a well-known certificate authority to enhance their brand's reputation.

ServiceNow custom url, lets encrypt, change to other CA

 set custom url:

https://docs.servicenow.com/bundle/washingtondc-platform-security/page/integrate/authentication/task/configure-custom-url.html

Add a custom URL to your instance configuration to use instead of your ServiceNow URL.

Before you begin

Role required: admin

You must activate the custom URL plugin and have purchased or registered a URL before adding the custom URL to your instance.

Procedure

  1. Navigate to All > Custom URL > Custom URLs.
  2. You should either:
    • Click New to associate a new domain name that is new to your instance.
    • Select a custom URL already set up to set as your instance URL.
  3. Fill in the appropriate fields:

    A custom URL should activate within six hours on your instance. A background job polls for custom URL job completion every 30 minutes.

Also need to contact support.


*CNAME record for the sub domain



*********************************
finished domain will have cert from lets encrypt, to change, contact support or use 
plugin 

https://medium.com/@aashishatrey/a-custom-ssl-for-your-servicenow-custom-url-6e9b5bfd9898

  1. Install the ServiceNow Infrastructure Security Settings (com.glide.infrastructure_security) plugin

Tuesday, 25 June 2024

servicenow table api supply utc time

               sysparm_display_value=true

              sysparm_query=


                sys_created_on>=2024-06-20+23:10:17^sys_created_on<=2024-06-20+23:27:10

              sysparm_limit=10000

              sysparm_offset=0



sysparm_display_value=true (servicenow api user time zone->not defined -> system time -> not defined -> pacific)

sysparm_display_value=all (returns UTC and servicenow api timezone)

servicenow add comments on remove attachment

 show remove attachment

https://www.servicenow.com/community/service-management-forum/how-to-publish-in-work-notes-when-an-attachment-is-deleted/m-p/395206



Create a Business Rule on the "sys_attachment" table. This will log a work note in the record that it was removed.

-Name: "Delete Attachment - Update Record"

-When: Before

-Delete: true




updateRecordForAttachment();// calling this function before deleting 

function updateRecordForAttachment(){

 var gr = new GlideRecord(current.table_name);//if you want only for a particular table you can even add a condition in BR to run only for that table 

   if(gr.get(current.table_sys_id)){

  gr.work_notes = "Attachment: " + current.file_name + " has been removed.";

  gr.update();

   }

}


Friday, 21 June 2024

servicenow max file size

 --------------------------------------------------------------------------------------------------------------------------

servicenow file attachment max is 1GB

https://www.servicenow.com/community/training-and-certifications/attachment-count-limit-and-size-limit-on-records-issues/m-p/2813367


but u can change it in sys properties, you can change it to any size 


https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0718101


System Properties > Security.


The Security Properties page for the instance will appear.  Locate the property on the page with the heading "Maximum file attachment size in megabytes". In this field, you can change the 

servicenow string max size 32 MB and fix

 servicenow string object is 32MB

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0749085


can run the above example using background script:



fix:

https://www.servicenow.com/community/now-platform-forum/attachment-size-limit-for-outbound-soap-messages/m-p/1082038


glide.size.aware.max_size.org.mozilla.javascript.NativeString -> 83886080 

glide.size.aware.max_size.java.lang.String  - >  83886080

Servicenow getvalue

 servicenow getvalue()




getValue()


https://www.servicenow.com/community/developer-blog/servicenow-importance-of-getvalue-and-getdisplayvalue-method/ba-p/2333471


The "getValue()" method returns a string representation of the data in the field. This is the safest way to ensure you are putting the proper data into the Array, or any other variable. The issue is found more often in code when data is pushed into an Array because you are typically looping through multiple records, hence changing the "view" of the data, but it can happen anywhere.




parseInt() on those that is integer, but getValue()  returned as string without parseInt(), "1" + 1 = "11"

https://www.servicenow.com/community/developer-forum/how-to-convert-field-value-from-string-to-integer/m-p/2501787

var intValue = parseInt(sourceValue);


Monday, 17 June 2024

servicenow table API . inbound API using oauth

oauth set up

https://docs.servicenow.com/bundle/tokyo-api-reference/page/integrate/inbound-rest/task/t_EnableOAuthWithREST.html


Procedure


Activate the OAuth 2.0 plugin.

Set the system property com.snc.platform.security.oauth.is.active to true.

Navigate to System OAuth > Application Registry.

Click New and then click Create an OAuth API endpoint for external clients.

Record the client_id and client_secret values from the previous step to use when requesting an access token.

To get an access token, use your REST client, such as cURL or Postman, to send a request to the OAuth endpoint (oauth_token.do).

Format the request as a URL-encoded HTTP POST body and include the required parameters.


Record the access token and refresh token from the response.

Submit the access token with subsequent REST requests.



https://docs.servicenow.com/bundle/tokyo-api-reference/page/integrate/inbound-rest/reference/r_RESTOAuthExample.html



servicenow inbount API response :


https://docs.servicenow.com/bundle/vancouver-api-reference/page/app-store/dev_portal/API_reference/ScriptableServiceResponseBuilder/concept/c_ScriptableServiceResponseBuilder.html


oauth profile need to be set up as useraccount


ServiceNow Oauth example: https://docs.servicenow.com/bundle/washingtondc-api-reference/page/integrate/inbound-rest/reference/r_RESTOAuthExample.html


In this example, the OAuth token has a client_id of a329c4515612210071a5e0c298ee2be8 and a client_secret of password22.


Getting an access token

Explain this code

curl -d "grant_type=password&client_id=a329c4515612210071a5e0c298ee2be8&client_secret=password22&username=RESTUser&password=RESTUserPassword"  https://<instance>.service-now.com/oauth_token.do

Sample token response

Explain this code

{

:"scope": "useraccount",

:"token_type": "Bearer",

:"expires_in": 1799,

:"refresh_token": "jZPdkEVrWvtMjrspldNjIS0uWM4D7QV9mgmcQXDVo5Qa_GVvmdR6NOp7OM038EHJnd6nZpWocFer1NcJz4zwdw",

:"access_token": "2wRlsRCT2SYjCCJP91kwo2EFzj5qg4O3I3aC09e0-0hz6Ib3YK7If-LMiNorNuglfqbkL4AfkYC92KYHUCcbpQ"

}

REST request with OAuth token

Explain this code

curl -H "Accept:application/json" -H "Authorization:Bearer 2wRlsRCT2SYjCCJP91kwo2EFzj5qg4O3I3aC09e0-0hz6Ib3YK7If-LMiNorNuglfqbkL4AfkYC92KYHUCcbpQ"  "https://<instance>.service-now.com/api/now/table/incident


Thursday, 13 June 2024

servicenow update multiple and using gr.attribute

 servicenow 


gliderecord 


        var gr = new GlideRecord(data['table_name']);

gr.sys_id is an object


it can be used in servicenow code like update

gr.sys_id = xxx


but it wont work when pushing to array cause its an object


var a = []

a.push(gr.sys_id) // wrong


should use a.push(gr.getValue('sys_id'))


//  update multiple:

https://www.servicenow.com/community/developer-articles/updatemultiple-operation-optimizing-your-code/ta-p/2323884


var gr = new GlideRecord('sys_user')


gr.addQuery('name','STARTSWITH', 's');


gr.query();


gr.setValue('first_name', gs.first_name + '  updated');


gr.updateMultiple(); 



servicenow table API

 show table API



add syslog_transaction to allow API call :

https://www.servicenow.com/community/now-platform-forum/why-can-i-not-see-the-syslog-transaction-table-in-the-rest-api/td-p/1057679

glide.ui.permitted_tables



query:


https://docs.servicenow.com/bundle/washingtondc-api-reference/page/integrate/inbound-rest/concept/c_TableAPI.html



dates:

https://www.servicenow.com/community/developer-forum/is-there-any-way-to-query-the-rest-api-using-utc-dates/m-p/1431782




display value to true to show request time (PST)


https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0789000

servicenow timezone, set timezone

 timezone:

 If you have not defined a time zone for this property, America/Los Angeles is the default.

 https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/time/task/t_SetASystemTimeZone.html#:~:text=By%20default%2C%20the%20field%20is,Los%20Angeles%20is%20the%20default.&text=Add%20a%20time%20zone%20in,values%2C%20see%20Time%20zone%20representation.

 

 define time zone:

 system property -> system

 https://www.servicenow.com/community/itsm-forum/how-to-know-the-instance-time-zone/td-p/793187

 

this also sets all users timezone, but can be override on user to user bases. I.E if a particular user sets his/own timezone in user detail

 

 recordGR.getValue('sys_created_on') -> returns UTC time 


recordGR.sys_created_on.getDisplayValue() -> returns user's time


https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/time/task/t_SetASystemTimeZone.html#:~:text=By%20default%2C%20the%20field%20is,Los%20Angeles%20is%20the%20default.&text=Add%20a%20time%20zone%20in,values%2C%20see%20Time%20zone%20representation.


getDisplayValue() will either use user timezone if set or system default time zone in system properties

https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/time/task/t_SetASystemTimeZone.html



instance time zone :

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideSystemAPI#r_GS-dateGenerate_S_S

dateGenerate

gs.dateGenerate(<input_date>) assumes input_data is in current user timezone(api user) or logged in user, (user detail) if not set it will system time zone (if not set its pacfific time), then covert to UTC 

https://www.servicenow.com/community/now-platform-forum/table-api-get-not-returning-correct-results-when-filtering-based/m-p/2408252



sysparm_display_value will display utc dates stored in db into user timezeone 


system default timezone of the user -> empty -> system propreties -> system -> PST

https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/time/task/t_SetASystemTimeZone.html#:~:text=By%20default%2C%20the%20field%20is,Los%20Angeles%20is%20the%20default.&text=Add%20a%20time%20zone%20in,values%2C%20see%20Time%20zone%20representation.


Servicenow attachment

 


servicenow glidesystattache(mostly scoped, delete can be used as global)


delete to be used as global:

https://www.servicenow.com/community/developer-forum/remove-attachments-using-glidesysattachment/m-p/1919541

https://developer.servicenow.com/dev.do#!/reference/api/utah/server_legacy/GlideSysAttachmentGlobalAPI#GSA-deleteAttachment_S?navFilter=attach


        var gr = new GlideRecord(table_name);

        gr.addQuery('sys_id', table_rec_sys_id);

        gr.query();

        if (gr.next()) {

            var attach = new GlideSysAttachment();

            attach.deleteAll(gr);

        }


scoped:

https://developer.servicenow.com/dev.do#!/reference/api/utah/server_legacy/GlideSysAttachmentGlobalAPI?navFilter=attach


servicenow string util (global scoped)

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server/no-namespace/GlideStringUtilScopedAPI#GSUS-isBase64_S

*************************************************************************************************************************************


Servicenow global create attachment using binary(*might not always work):


script include reference  global.Attachment


https://www.servicenow.com/community/developer-forum/decoding-base64-encoded-file-and-writing-it-to-sys-attachment/m-p/2122987



var StringUtil = new GlideStringUtil();

var attachment = new Attachment();

if (JSUtil.notNil(source.u_attachment1_name))

attachment.write('incident',target.sys_id, source.u_attachment1_name, '', StringUtil.base64DecodeAsBytes(source.u_attachment1));

********************************************************************************************************************************************

Servicenow global scope use base64 to create attachment

https://www.servicenow.com/community/developer-forum/how-can-i-create-an-attachment-from-script/m-p/1443004/page/2

ecc queue create attachment, uses for base64


**********for servicenow, might need to use ur own base64tobin(), combinebin(), bintobase64() ********** refer to 

org.mozilla.javascript.NativeArray to byte


 The error message "can't convert org.mozilla.javascript.NativeArray to byte" typically occurs when working with JavaScript in environments that use the Rhino engine or similar JavaScript interpreters in Java contexts, such as ServiceNow's scripting environment. This environment may not directly support certain JavaScript data types or operations as expected in a standard browser-based JavaScript engine.


Here’s how to handle and convert JavaScript arrays to binary data without encountering such errors, specifically for environments like ServiceNow.


***********************************

var eccGr = new GlideRecord('ecc_queue');



eccGr.initialize();



eccGr.setValue('agent', 'AttachmentCreator');



eccGr.setValue('topic', 'AttachmentCreator');



eccGr.setValue('name', fileName+':'+contentType);



eccGr.setValue('source', tableName+':'+tableSysId);



eccGr.setValue('payload', content);


servicenow can't convert org.mozilla.javascript.NativeArray to byte

 The error message "can't convert org.mozilla.javascript.NativeArray to byte" typically occurs when working with JavaScript in environments that use the Rhino engine or similar JavaScript interpreters in Java contexts, such as ServiceNow's scripting environment. This environment may not directly support certain JavaScript data types or operations as expected in a standard browser-based JavaScript engine.

Here’s how to handle and convert JavaScript arrays to binary data without encountering such errors, specifically for environments like ServiceNow.

Understanding the Issue

  • NativeArray in Rhino: In environments like Rhino (used in ServiceNow), a NativeArray is a JavaScript array object that needs special handling to be converted into Java-compatible types.
  • Binary Conversion: The challenge is converting a NativeArray to a byte array or similar structure that can be processed as binary data.

Steps to Handle the Conversion

To combine two Base64 strings in a JavaScript environment like ServiceNow, you can:

  1. Decode the Base64 strings into binary data.
  2. Convert the binary data to a JavaScript array.
  3. Combine the arrays and convert them back to a Base64 string.

Here’s a step-by-step guide to achieve this:

Step 1: Decode Base64 to Binary Data

Since you can’t use atob, you need to manually decode the Base64 strings.

javascript
function decodeBase64(base64) { var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; var output = []; var buffer = 0, bitsCollected = 0, value; for (var i = 0; i < base64.length; i++) { value = chars.indexOf(base64[i]); if (value === -1) { continue; } buffer = (buffer << 6) | value; bitsCollected += 6; if (bitsCollected >= 8) { bitsCollected -= 8; output.push((buffer >>> bitsCollected) & 0xFF); } } return output; }

Step 2: Convert Base64 String to JavaScript Array

Decode the Base64 string into a NativeArray.

javascript
var base64String1 = "SGVsbG8s"; var base64String2 = "IHdvcmxkIQ=="; var byteArray1 = decodeBase64(base64String1); var byteArray2 = decodeBase64(base64String2);

Step 3: Combine the Binary Arrays

Combine the binary arrays into one.

javascript
function combineArrays(arr1, arr2) { var combined = []; for (var i = 0; i < arr1.length; i++) { combined.push(arr1[i]); } for (var j = 0; j < arr2.length; j++) { combined.push(arr2[j]); } return combined; } var combinedArray = combineArrays(byteArray1, byteArray2);

Step 4: Re-encode to Base64

Encode the combined array back to Base64.

javascript
function encodeBase64(array) { var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; var output = ''; for (var i = 0; i < array.length; i += 3) { var byte1 = array[i] & 0xFF; var byte2 = i + 1 < array.length ? array[i + 1] & 0xFF : 0; var byte3 = i + 2 < array.length ? array[i + 2] & 0xFF : 0; var triplet = (byte1 << 16) | (byte2 << 8) | byte3; output += chars[(triplet >> 18) & 0x3F]; output += chars[(triplet >> 12) & 0x3F]; output += (i + 1 < array.length) ? chars[(triplet >> 6) & 0x3F] : '='; output += (i + 2 < array.length) ? chars[triplet & 0x3F] : '='; } return output; } var combinedBase64String = encodeBase64(combinedArray); console.log(combinedBase64String);

Final Solution

Combine the two Base64-encoded strings and convert them back into a single Base64 string without using String, Uint8Array, or atob functions, avoiding NativeArray to byte conversion issues.

javascript
function combineBase64Segments(base64String1, base64String2) { var byteArray1 = decodeBase64(base64String1); var byteArray2 = decodeBase64(base64String2); var combinedArray = combineArrays(byteArray1, byteArray2); return encodeBase64(combinedArray); } // Example usage var base64String1 = "SGVsbG8s"; // "Hello," var base64String2 = "IHdvcmxkIQ=="; // " world!" var combinedBase64String = combineBase64Segments(base64String1, base64String2); console.log(combinedBase64String); // Expected output: "SGVsbG8sIHdvcmxkIQ=="

Conclusion

By decoding Base64 strings to binary, concatenating them, and re-encoding, you can avoid issues related to NativeArray conversion and maintain compatibility with JavaScript environments like ServiceNow. This method ensures that binary data is correctly managed and combined into a valid Base64 string.

ServiceNOW table API and date time

 timezone:

 If you have not defined a time zone for this property, America/Los Angeles is the default.

 https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/time/task/t_SetASystemTimeZone.html#:~:text=By%20default%2C%20the%20field%20is,Los%20Angeles%20is%20the%20default.&text=Add%20a%20time%20zone%20in,values%2C%20see%20Time%20zone%20representation.

 

 define time zone:

 system property -> system

 https://www.servicenow.com/community/itsm-forum/how-to-know-the-instance-time-zone/td-p/793187

 

 

 recordGR.getValue('sys_created_on') -> returns UTC time 


recordGR.sys_created_on.getDisplayValue() -> returns user's time


https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/time/task/t_SetASystemTimeZone.html#:~:text=By%20default%2C%20the%20field%20is,Los%20Angeles%20is%20the%20default.&text=Add%20a%20time%20zone%20in,values%2C%20see%20Time%20zone%20representation.


getDisplayValue() will either use user timezone if set or system default time zone in system properties

 ---------------------------


Servicenow table API:

query by dates:

https://www.servicenow.com/community/developer-forum/rest-api-get-using-greater-than-for-dates/m-p/1676011

https://www.servicenow.com/community/developer-forum/how-to-query-table-with-utc-timestamp/m-p/1639984/page/2


instance time zone :

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideSystemAPI#r_GS-dateGenerate_S_S

dateGenerate

Generates a date and time for the specified date in GMT.



curl "https://fortinetdev.servicenowservices.com/api/now/table/syslog_transaction?sysparm_query=sys_created_on>javascript:gs.dateGenerate('2024-06-13','10:53:00')&sysparm_display_value=true&sysparm_limit=5" \

--request GET \

--header "Accept:application/json" \

--user 'user':'pwd'



# system default timezone of the user -> empty -> system propreties -> system -> PST

https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/time/task/t_SetASystemTimeZone.html#:~:text=By%20default%2C%20the%20field%20is,Los%20Angeles%20is%20the%20default.&text=Add%20a%20time%20zone%20in,values%2C%20see%20Time%20zone%20representation.



query:


https://docs.servicenow.com/bundle/washingtondc-api-reference/page/integrate/inbound-rest/concept/c_TableAPI.html



dates:

https://www.servicenow.com/community/developer-forum/is-there-any-way-to-query-the-rest-api-using-utc-dates/m-p/1431782




display value to true to show request time (PST)


https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0789000






created <new_role> role assign to syslog_transcation



add syslog_transaction to allow API call :

https://www.servicenow.com/community/now-platform-forum/why-can-i-not-see-the-syslog-transaction-table-in-the-rest-api/td-p/1057679

glide.ui.permitted_tables


Tuesday, 11 June 2024

Servicenow forcefully change sys_updated_by in regualr table and additional comments

 ServiceNow forcefully change sys_updated_by

https://www.servicenow.com/community/developer-forum/fixscript-to-set-sys-updated-by-not-working/m-p/2446671


gr.autoSysFields(false);



gr.sys_updated_by = 'myusername'

gr.update();

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1113503




Servicenow change addtional comments uer

additional comment user is in sys_history_set

https://www.servicenow.com/community/sysadmin-forum/changing-the-user-name-tagged-in-the-work-notes-or-additional/m-p/2366111


https://www.servicenow.com/community/developer-forum/can-you-change-the-name-of-user-to-system-in-work-notes/m-p/2194112


https://www.servicenow.com/community/developer-forum/can-you-change-the-name-of-user-to-system-in-work-notes/m-p/2194112


var myUser = gs.getSession().impersonate("62826bf03710200044e0bfc8bcbe5df1");// sys_id of user who you want to be static or system.

// applies to all other function calls **** within a script execution


Friday, 31 May 2024

servicenow glide query In , faster delete

 var C_LIST = [

'A', 'B'

];


-----------------

var gr = new GlideRecord("test");

gr.addQuery('u_event_type', 'IN', C_LIST.join());


-------------------

var NameList = ['A', 'B']

        gr.addEncodedQuery('column_name' + NameList);

       gr.query()

------------

faster delete

        gr.query();

        gr.setWorkflow(false);

        gr.deleteMultiple();


-----------------

add or condition 

            gr.addOrCondition('name, 'A');



servicenow glide date time

 https://docs.servicenow.com/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_reference/GlideDateTime/concept/c_GlideDateTimeAPI.html

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0594666

To create a GlideDateTime object with the current date and time, do not provide a parameter. Simply call the constructor of the GlideDateTime class and the value is initialized to the current date and time.

// Do this
var dgt = new GlideDateTime();

Do not use gs.nowDateTime() to set a GlideDateTime object. The nowDateTime() method returns the date time in local format and the local time zone. The GlideDateTime object uses the date time in the internal format and UTC time zone.

//Not this
var gdt = new GlideDateTime(gs.nowDateTime());

glide date time is default UTC, you can set timezone :

https://www.servicenow.com/community/in-other-news/demystifying-glidedatetime-and-timezones-also-convert-dates-to/ba-p/2472586

var gdt = new GlideDateTime();
gdt.setTimeZone('US/Eastern');
gs.info(gdt.getDisplayValue());



GlideDateTime - getDisplayValue()

Gets the date and time value in the current user's display format and time zone.

Note: Referring to the GlideDateTime object directly returns the date and time value in the GMT time zone.
Parameters
NameTypeDescription
None
Returns
TypeDescription
ObjectDate and time in the user's format and time zone. Keep in mind when designing business rules or script includes that this method may return values in different formats for different users.

Example

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.info(gdt.getDisplayValue());