- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 04:21 AM
Hi,
I am trying to get the unique gliderecords based on client field using below script but it is not working. Can anyone help me here?
var gr = new GlideRecord('u_client_role_new');
gr.addEncodedQuery('u_module=Tooling Electronics^u_department=PUR (PURCHASING)^u_bu=Electronics^u_client!=undefined');
gr.orderBy('u_client_role');
gr.query();
gr.next();
var sys_ids = gr.sys_id;
gs.print(sys_ids);
var client = gr.u_client_role;
var client1=client;
gs.print(client);
while(gr.next()) {
//gs.print(gr.u_client_role);
gs.print(client1+' vs '+gr.u_client_role);
}
When i ran this script i am getting the result like below-
Here you can see that i am not re-assigning value of client but it is getting automatically re-assigned. I tried to do similar thing in browser console but autoreassigment in not happening there but in servicenow this re-assignment is happening automatically.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 04:55 AM
This is the old memory location issue where your the use of gr.field_name for a variable assignment is assigning the value as the memory location of the record instead of the text string you are expecting. To avoid this use getValue instead:
var gr = new GlideRecord('u_client_role_new');
gr.addEncodedQuery('u_module=Tooling Electronics^u_department=PUR (PURCHASING)^u_bu=Electronics^u_client!=undefined');
gr.orderBy('u_client_role');
gr.query();
gr.next();
var sys_ids = gr.getValue('sys_id');
gs.print(sys_ids);
var client = gr.getValue('u_client_role');
var client1=client;
gs.print(client);
while (gr.next()) {
gs.print(client1+' vs '+gr.getValue('u_client_role'));
}
This post does a good job of explaining the issue:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 04:55 AM
This is the old memory location issue where your the use of gr.field_name for a variable assignment is assigning the value as the memory location of the record instead of the text string you are expecting. To avoid this use getValue instead:
var gr = new GlideRecord('u_client_role_new');
gr.addEncodedQuery('u_module=Tooling Electronics^u_department=PUR (PURCHASING)^u_bu=Electronics^u_client!=undefined');
gr.orderBy('u_client_role');
gr.query();
gr.next();
var sys_ids = gr.getValue('sys_id');
gs.print(sys_ids);
var client = gr.getValue('u_client_role');
var client1=client;
gs.print(client);
while (gr.next()) {
gs.print(client1+' vs '+gr.getValue('u_client_role'));
}
This post does a good job of explaining the issue:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 05:13 AM
Thanks for the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 08:22 AM
You are welcome!