- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 07:03 AM
Hi,
I wote this code, but it gives the wrong input, but when I change the sequence, it works fine. Can you please provide me with insight?
var gr = new GlideRecord('sys_user');
gr.addQuery(producer.email, 'email');
gr.query();
if(gr.next()){
current.u_employee = gr.sys_id;
}
It works for this
var gr = new GlideRecord('sys_user');
gr.addQuery( 'email', producer.email);
gr.query();
if(gr.next()){
current.u_employee = gr.sys_id;
}
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 07:08 AM - edited 06-23-2025 07:14 AM
Hi @ServiceNow Use6,
Yes, sequence matters as first parameter ('email') should be a field on the GlideRecord table and added as a string in the script.
The second parameter is value stored in the field and can be string or dynamic (which is in your case, i.e. producer.email).
That's why the second version works: 'email' is the correct field name, and producer.email is the value you're querying. Always follow addQuery('field_name', value) — field name first, value second
Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 07:14 AM
Yes and that's how addQuery() works.
1st parameter is always the field name either a direct field of table or a dot walked field
2nd parameter is always the value to be compared.
check docs for more help
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 07:08 AM - edited 06-23-2025 07:14 AM
Hi @ServiceNow Use6,
Yes, sequence matters as first parameter ('email') should be a field on the GlideRecord table and added as a string in the script.
The second parameter is value stored in the field and can be string or dynamic (which is in your case, i.e. producer.email).
That's why the second version works: 'email' is the correct field name, and producer.email is the value you're querying. Always follow addQuery('field_name', value) — field name first, value second
Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 07:14 AM
Yes and that's how addQuery() works.
1st parameter is always the field name either a direct field of table or a dot walked field
2nd parameter is always the value to be compared.
check docs for more help
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader