
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
04-16-2024 12:16 AM - edited 04-16-2024 01:03 AM
Welcome to Scripting in ServiceNow Fundamentals at Knowledge24 Now Learning Pre Conference Training!
We will be using this forum to:
- Connect – You are welcome to introduce yourself using the COMMENT button and share your role within your organization and what you hope to get from this learning experience.
- Ask and answer questions - Please post comments or questions here using the COMMENT button. Classroom staff will respond to the best of their ability.
- Share resources – Let us share resources and links that will be valuable for future reference.
NOTE: Now Learning staff will stop monitoring this article on May 24.
- 1,590 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Everyone,
As the Instructor for the Scripting class, I just want to state that I am looking forward to seeing you all at pre-con and delivering the course to you.
If you are new to Scripting/JavaScript in general, you may want to check out the excellent Code Academy Free course for beginners: https://www.codecademy.com/learn/introduction-to-javascript
For ad-hoc JavaScript examples your may also want to refer to the W3 Schools JavaScript tutorial. This provides a resource to lookup various JavaScript language features and syntax: https://www.w3schools.com/js/
For those with more intermediate knowledge of JavaScript you may want to refer to the JavaScript in the ServiceNow platform series on YouTube: https://www.youtube.com/watch?v=62Nabpb94Jw
Let me confirm that going through these resources is not mandatory, but you may find them useful to support your knowledge and develop your scripting skills.
Finally, as my colleague Tim has stated, please use the forum to ask you questions and we will be pleased to answer.
Best wishes and see you all soon. Darren
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Darren,
Intro:
I am 'new' to JavaScript (last contact was 20 years ago [I am an old man at 73]). And 'new' to ServiceNow's handling of JavaScript. Work as an Administrator at WellSpan Health (York, AP) [my colleague Jamie Sherry will, also, be in attendance].
And, yes, I did 'sit' and happily passed the CSA exam last June.
I did move one process to production last week. It was a great teaching/learning tool. UI page/Script Includes/Scopes/client scripts/Ajax, etc. were involved. This effort was started by our implementation partner. The ''shell' of some things were already built. I just 'finished' it off.
My Questions:
The 'processing discussed below is occurring on a UI Page.
-->It accesses the 'jelly' HTML - creates dropdown lists where appropriate
How can one access the return value from a 'getXML(response)' call?
What is the 'context' (I assume server) of the 'answer' variable (or any other variable) within the 'response' function called by 'getXML?'
From 'research' I can process the value within the 'response)' function called by 'getXML.'
But, I could not 'seem' to access the 'answer'/result value outside of the 'response' function.
-->I created a 'global' variable -- it comes up as 'undefined' inside of the 'response' function.
I will stop here. I am in no way claiming to be 'knowledgeable' in this area. I am still in the 'look up'/research/ServiceNow Support/ChatGPT mode. no 'big muscle memory' -- yet.
**Really excited about attending the class and Learning!! The E-book looks excellent!!
Thanks,
John Spencer

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Regarding the "$0 Question": https://www.servicenow.com/community/in-other-news/syntax-editor-macros-a-tiny-thing-that-makes-the-...

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Following up on the previous comment, it seems like you can also use $1, $2 $3, .... to specify where the cursor should go in which order. Interestingly, $0 seems to always be last if you use $0 and any other $<number>. Can't find any documentation on this but it works!

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@John Spencer I think some of your questions will be addressed tomorrow when we go through Script Includes. But if any one them are still open after tomorrow's session, let me know!

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@ Kate B
To answer a question on the "Isolate Script" field for Client Scripts:
From the documentation (docs link)"New client scripts are run in strict mode, with direct DOM access disabled. Access to jQuery, prototype, and the window object are also disabled. To disable this on a per-script basis, configure this form and select the Isolate script check box."
So effectively, with "Isolate Script" enabled, we are ensuring best practice compliance by restricting access to things like jQuery and other JS libraries, which ServiceNow does not consider best practice. If you uncheck "Isolate Script," you gain access to these things but also potentially introduce best practice violations and security issues.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Can you confirm whether catalog scripts, catalog client scripts, and advanced (scripted) UI policies would work for mobile apps (Now Mobile and Mobile Agent)? Both of these indicate that at least client scripts would not.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @kbaldwin ! It depends on the mobile app. Older ones can use these things, but that's not the case for these more modern mobile apps you've listed. You would use the Mobile Studio to configure them, and that works quite differently from the desktop options we're discussing in this class.
For more info on the mobile studio and development in there, here's a learning path from NowLearning: https://nowlearning.servicenow.com/lxp/en/now-platform/mobile-development-essentials?id=learning_pat...
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This really isn't a question, I wanted to thank Darren for the additional 'REST Request with Public Web Service' lab! This technique could be really useful for integration data!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
For whoever asked about converting an encoded query back into a normal filter query in a list view, it is possible but it does require a 3rd party browser extension called SN UTILs. It's written and maintained by a ServiceNow employee, Arnoud Kooi. I HIGHLY recommend it. It's an insanely good browser extension and incredibly useful if you're doing any scripting. (Typing /tn to show technical names next to fields is *chef's kiss*)
To convert an encoded query back to a regular filter query, you have to double click next to the filter conditions (or anywhere in the lighter gray bar), and then paste the encoded query in the newly alert window. It'll fully reconstruct the original query.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks @Tim Witkovsky for putting that here! Super useful 🙂
@ Steve I.
I've put a quick example together for your question regarding one GlideRecord looping through the results of another GlideRecord here. Let me know if that's what you needed or not!
try {
//for x groups loop through their members and tell me their email addresses
var groupGr = new GlideRecord("sys_user_group"); //initiate GlideRecord on the groups table
groupGr.addActiveQuery(); //only get the active groups
groupGr.addNotNullQuery('manager'); //only get groups that have a manager
groupGr.query();
while (groupGr.next()) { //loop through the groups
var memberEmails = ''; //initiate string variable to hold emails
var groupMemberGr = new GlideRecord('sys_user_grmember'); //initiate GlideRecord on the group member table
groupMemberGr.addQuery('group', groupGr.getValue('sys_id')); //filter for all members of our current group, by filtering for the member records that have the current group's sys_id
groupMemberGr.query();
while (groupMemberGr.next()) { //loop through all members of current group
memberEmails = memberEmails + groupMemberGr.user.email + '\n'; //add current group member's email to the variable and add a line break for easier readability
}
gs.info('Group member emails for group ' + groupGr.getValue('name') + ': \n' + memberEmails); //write information to the log for now
}
} catch (e) {
gs.error('Error in <ScriptType> <ScriptName> <FunctionName>: ' + e); //Try-catch with error logging for good practice :)
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Tim!
Thank you very much for quick respond and useful information.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@ Vishal GlideQuery has the same functionality as GlideRecord for disabling the execution of Business Rules or Server-side logic in general. In GlideQuery the method is called "disableWorkflow"
https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server/no-namespace/GlideQueryG...

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
More info on our certification offering during Knowledge 2024: https://servicenow.swoogo.com/Knowledge24Certification
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Tim Kulhavy Thank you for sharing, yet it works!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Question: This is an example Use case related to GlideDateTime.
1. If my manager "Tim" is based out of Germany and his ServiceNow preference is set to local German Time.
2. My manager need me (I am based out of Las Vegas) to perform a Change Request on Saturday 05/11/2024 7 pm CDT.
3. My manager will create a Change request for me.
Question: How ServiceNow can help my manager to select Change request start and end date as per US Central Time zone.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@jaswalvishal106 Great question! Thank you for the promotion. I have always wanted to be a manager!
The easiest, no-code solution I can think of is for the manager (me) to change his user preference to the desired timezone (CDT), create the change request, and put in the value (05/11/2024 7PM).
After that, he changes his timezone preference back to his normal desired timezone. The field should then show the date & time in his timezone (German time), but it will show for you, Vishal, in your timezone (CDT).
Does that make sense so far?