- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 02:30 AM
Hi all,
i want to search either username or email address , after click on search i will search username in user_id or email in email addess if one of those exist then it with return the user company name and sysid, i will try it on client script or script include
ui page:
var sname = gel('myname').value;
var semail = gel('myemail').value;
alert("Values-sname: " +sname); --- getting this value
alert("Values-semail: " +semail); -- getting this value
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 02:58 AM
Hello @Debarpita,
There are a few possible ways to query one parameter out of two in a UI page in ServiceNow.
One way is to use the GlideRecord object, which allows you to query, insert, update, and delete records from a table. You can use the addQuery method to add conditions to your query, such as matching the username or email address to the input values. For example, you can use something like this:
//Create a GlideRecord object for the sys_user table
var gr = new GlideRecord('sys_user');
//Add a condition to query by username or email address
gr.addQuery('user_name', sname);
gr.addOrCondition('email', semail);
//Execute the query
gr.query();
//Iterate through the results
while (gr.next()) {
//Do something with the records returned
alert('User company name: ' + gr.company.getDisplayValue());
alert('User sys_id: ' + gr.sys_id);
}
Another way is to use the NavigationContext object, which allows you to access the query string parameters from the URL of the page. You can use the QueryString property to get the values of the parameters, such as username or email address. For example, you can use something like this:
//Get the query string parameters from the URL
var sname = NavigationContext.QueryString['username'];
var semail = NavigationContext.QueryString['email'];
//Create a GlideRecord object for the sys_user table
var gr = new GlideRecord('sys_user');
//Add a condition to query by username or email address
gr.addQuery('user_name', sname);
gr.addOrCondition('email', semail);
//Execute the query
gr.query();
//Iterate through the results
while (gr.next()) {
//Do something with the records returned
alert('User company name: ' + gr.company.getDisplayValue());
alert('User sys_id: ' + gr.sys_id);
}
You can read more about the NavigationContext object and its properties in this article.
A third way is to use the NavigationEventArgs object, which allows you to pass data between pages using properties. You can use this object to set or get properties from the source or destination page, such as username or email address. For example, you can use something like this:
//In the source page
//Create a NavigationEventArgs object
var args = new NavigationEventArgs();
//Set properties for username and email address
args.username = sname;
args.email = semail;
//Navigate to the destination page with arguments
window.location.href = "/page.html?" + args.toString();
//In the destination page
//Get the NavigationEventArgs object from the URL
var args = NavigationEventArgs.fromCurrent();
//Get properties for username and email address
var sname = args.username;
var semail = args.email;
//Create a GlideRecord object for the sys_user table
var gr = new GlideRecord('sys_user');
//Add a condition to query by username or email address
gr.addQuery('user_name', sname);
gr.addOrCondition('email', semail);
//Execute the query
gr.query();
//Iterate through the results
while (gr.next()) {
//Do something with the records returned
alert('User company name: ' + gr.company.getDisplayValue());
alert('User sys_id: ' + gr.sys_id);
}
You can read more about the NavigationEventArgs object and its methods in this article.
Hope this helps.
Kind Regards,
Swarnadeep Nandy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 02:58 AM
Hello @Debarpita,
There are a few possible ways to query one parameter out of two in a UI page in ServiceNow.
One way is to use the GlideRecord object, which allows you to query, insert, update, and delete records from a table. You can use the addQuery method to add conditions to your query, such as matching the username or email address to the input values. For example, you can use something like this:
//Create a GlideRecord object for the sys_user table
var gr = new GlideRecord('sys_user');
//Add a condition to query by username or email address
gr.addQuery('user_name', sname);
gr.addOrCondition('email', semail);
//Execute the query
gr.query();
//Iterate through the results
while (gr.next()) {
//Do something with the records returned
alert('User company name: ' + gr.company.getDisplayValue());
alert('User sys_id: ' + gr.sys_id);
}
Another way is to use the NavigationContext object, which allows you to access the query string parameters from the URL of the page. You can use the QueryString property to get the values of the parameters, such as username or email address. For example, you can use something like this:
//Get the query string parameters from the URL
var sname = NavigationContext.QueryString['username'];
var semail = NavigationContext.QueryString['email'];
//Create a GlideRecord object for the sys_user table
var gr = new GlideRecord('sys_user');
//Add a condition to query by username or email address
gr.addQuery('user_name', sname);
gr.addOrCondition('email', semail);
//Execute the query
gr.query();
//Iterate through the results
while (gr.next()) {
//Do something with the records returned
alert('User company name: ' + gr.company.getDisplayValue());
alert('User sys_id: ' + gr.sys_id);
}
You can read more about the NavigationContext object and its properties in this article.
A third way is to use the NavigationEventArgs object, which allows you to pass data between pages using properties. You can use this object to set or get properties from the source or destination page, such as username or email address. For example, you can use something like this:
//In the source page
//Create a NavigationEventArgs object
var args = new NavigationEventArgs();
//Set properties for username and email address
args.username = sname;
args.email = semail;
//Navigate to the destination page with arguments
window.location.href = "/page.html?" + args.toString();
//In the destination page
//Get the NavigationEventArgs object from the URL
var args = NavigationEventArgs.fromCurrent();
//Get properties for username and email address
var sname = args.username;
var semail = args.email;
//Create a GlideRecord object for the sys_user table
var gr = new GlideRecord('sys_user');
//Add a condition to query by username or email address
gr.addQuery('user_name', sname);
gr.addOrCondition('email', semail);
//Execute the query
gr.query();
//Iterate through the results
while (gr.next()) {
//Do something with the records returned
alert('User company name: ' + gr.company.getDisplayValue());
alert('User sys_id: ' + gr.sys_id);
}
You can read more about the NavigationEventArgs object and its methods in this article.
Hope this helps.
Kind Regards,
Swarnadeep Nandy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 03:50 AM
I tried three of them , i am not getting alert after while Kindly suggest another way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 03:37 AM
I will try all and let you in sometime.