I was trying to run the below code in JavaScript Executor. but as an output, it returns "undefined".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2022 10:31 AM
I was trying to run the below code in JavaScript Executor. but as an output, it returns "undefined". any idea what I need to do??
gname = g_form.getValue('assignment_group');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',gname);
gr.query();
while(gr.next())
{
var user = gr.user.name;
alert(user);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2022 10:36 AM - edited 11-05-2022 10:41 AM
Hi @Ajay07
JavaScript Executor tests client side scripting. Refer link below:
And GlideRecord() is a server side API so it won't work on JavaScript Executor.
If you want to test it, you can use background Script with specific record number you can test GlideRecord.
Refer code below:
var inc = GlideRecord('incident');
inc.addQuery('number','INC0003424'); // put your Incident number for which you are trying to run javascript executor
inc.query();
if(inc.next())
{
gname = inc.assignment_group;
var grpMember = new GlideRecord('sys_user_grmember');
grpMember.addQuery('group',gname);
grpMember.query();
while(grpMember.next())
{
var user = grpMember.user.name;
gs.info(user); // gs.print(user) will also work in background script
}
}
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2022 11:26 AM
Hi, @AnubhavRitolia Thanks!!
I have one more doubt, First, I want to fetch all the users whoever is supporting the respective group and after that, I want to compare the current time with the From time and To time of the group member. if the current time is between From and To then it will set the member name as Assigned to. so I was writing this code in UI Action. it's not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2022 12:39 PM
Hi @Ajay07
As mentioned, you cannot use both client side and server side script together.
You are using g_form (client side) and GlideRecord() and GlideDateTime() server side APIs together.
What is your UI Action type? Client or Server.
Also try to add Logs or alerts to see where you are getting stuck.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2022 12:21 AM
Hi @Ajay07
As I have solved your original query related to JavaScript Executor, can you please mark my solution as Correct Answer.
For another query you can raise different question and we can have seperate tread to resolve it. Feel free to share the link of new question on private message also or tag me so I can help you with that also.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023