
- 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-21-2025 07:31 AM
Hey Johnny! It is still not opening anything in the workspace. i get the infomessage like before. QUick question, are you using actionname anywhere?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 09:22 PM
were you found the solution

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2025 08:37 PM
Yeah i did! I actually used client script in ui action instead of workspace script. Didn't use ajax as server side call was done directly.
- 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-21-2025 07:32 AM
Hey Ankur, it is still not opening anything in workspace. can you check my client script that i provided up?