
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 04:20 PM
I am working on a workspace where I have created a custom table with one field. Field is a lookup number. What I wanted to achieve is, if a user enters a number and clicks the Lookup search button then my script would search for that number in contact table and opens the record in a new tab in the workspace. This is my ui action workspace script.
And this is my server script where i am getting the sys_id of the record
I have checked all the values in UI action, script include is also client calable but my button doesn't execute anything.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 08:40 PM
@Shubham Gagneja I was able to achieve this in my pdi with below code, you might need to do some changes to your code as follows.
UI Action:
UI Action script
function onClick(g_form) {
g_form.addInfoMessage('Search button clicked!');
var tableName = "sys_user";
var contactNumber = g_form.getValue("close_notes");
if (!contactNumber) {
g_form.addErrorMessage("Please enter a contact number.");
return;
}
var ContactCall = new GlideAjax("ContactSearchAjax");
ContactCall.addParam("sysparm_name", "findContact");
ContactCall.addParam("sysparm_ContactNum", contactNumber);
ContactCall.getXMLAnswer(_handleResponse);
function _handleResponse(answer) {
if (answer) {
var ContactSysId = answer;
if (ContactSysId)
g_aw.openRecord(tableName, ContactSysId); // Open contact profile in workspace
}
}
}
your script include seems to be incorrect
Script include code
var ContactSearchAjax = Class.create();
ContactSearchAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
findContact:function() {
gs.info("*** Script log entered");
var mobNo = this.getParameter('sysparm_ContactNum');
gs.info("*** Script log " + mobNo);
var gr = new GlideRecord("sys_user");
gr.addQuery("mobile_phone", mobNo);
gr.query();
if (gr.next()) {
gs.info("*** Script log " + gr.getUniqueValue());
return gr.getUniqueValue();
}
},
type: 'ContactSearchAjax'
});
Please change the parameters and table name as per your instance, I've used the ootb user table for this
Please mark it as helpful or correct if it helped you resolve the issue or worked for you.
Johnny
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 09:53 PM
the way how you are getting the value from Ajax, it's wrong
Also field contact_number on current form is string type
update as this
var ContactSearchAjax= Class.create();
ContactSearchAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
findContact: function() {
var ContactNum = this.getParameter('ContactNum');
var gr = new GlideRecord("x_ccn_contact");
gr.addQuery("contact_number", ContactNum);
gr.query();
if (gr.next()) {
return gr.getUniqueValue();
}
return "";
}
});
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
‎03-20-2025 04:43 PM
1. What are you trying to achieve here? If it is just opening a record in new tab, then why are you not using the OOTB global search option?
2. Which version are you in? If Xanadu, refer this link https://www.servicenow.com/docs/bundle/xanadu-it-service-management/page/product/incident-management...
Please mark it as helpful or correct if it helped you resolve the issue or worked for you.
Johnny
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 07:13 PM
Like i mentioned, if I enter a user_name in my field and click on the ui action, I am trying to open a record based on the user_name that I entered. I need to use this ux and the field for that lookup search.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 08:14 PM - edited ‎03-20-2025 08:16 PM
@Shubham Gagneja can you share your script include as well here and the screenshots of the UI action that you have created.
I'm not sure if you have noticed, there are lot of extra spaces like here:
ContactCall .addParam("sysparm_name", "findContact");
Johnny
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 08:40 PM
@Shubham Gagneja I was able to achieve this in my pdi with below code, you might need to do some changes to your code as follows.
UI Action:
UI Action script
function onClick(g_form) {
g_form.addInfoMessage('Search button clicked!');
var tableName = "sys_user";
var contactNumber = g_form.getValue("close_notes");
if (!contactNumber) {
g_form.addErrorMessage("Please enter a contact number.");
return;
}
var ContactCall = new GlideAjax("ContactSearchAjax");
ContactCall.addParam("sysparm_name", "findContact");
ContactCall.addParam("sysparm_ContactNum", contactNumber);
ContactCall.getXMLAnswer(_handleResponse);
function _handleResponse(answer) {
if (answer) {
var ContactSysId = answer;
if (ContactSysId)
g_aw.openRecord(tableName, ContactSysId); // Open contact profile in workspace
}
}
}
your script include seems to be incorrect
Script include code
var ContactSearchAjax = Class.create();
ContactSearchAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
findContact:function() {
gs.info("*** Script log entered");
var mobNo = this.getParameter('sysparm_ContactNum');
gs.info("*** Script log " + mobNo);
var gr = new GlideRecord("sys_user");
gr.addQuery("mobile_phone", mobNo);
gr.query();
if (gr.next()) {
gs.info("*** Script log " + gr.getUniqueValue());
return gr.getUniqueValue();
}
},
type: 'ContactSearchAjax'
});
Please change the parameters and table name as per your instance, I've used the ootb user table for this
Please mark it as helpful or correct if it helped you resolve the issue or worked for you.
Johnny
Please mark this response as correct or helpful if it assisted you with your question.