
- 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 08:13 AM
in client script gs.info() won't work
Also for your UI action to work in workspace, you need to add code in workspace client script
Did you add code there?
function onClick(g_form) {
var tableName = "x_ccn_contact";
var contactNumber = g_form.getValue("contact_number"); // this field should be present in workspace view of your form/table
if (!contactNumber) {
g_form.addErrorMessage("Please enter a contact number.");
return;
}
var ContactCall = new GlideAjax("ContactSearchAjax");
ContactCall.addParam("sysparm_name", "findContact");
ContactCall.addParam("ContactNum", contactNumber);
ContactCall.getXMLAnswer(function(response) {
alert("GlideAjax Response " + response);
if (response) {
if (response) {
g_aw.openRecord(tableName, response); // Open contact profile in workspace
} else {
g_form.addErrorMessage('Contact not found.');
}
} else {
g_form.addErrorMessage('Error in GlideAjax call.');
}
});
}
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 08:30 AM
Still not working.
Check this!
my updated script include
My updated client script
and my wworkspace view
IT doesn't open anything!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2025 11:34 AM
Thanks @Ankur Bawiskar @JohnnySnow for the help! I used a different approach and its working now!