Workspace script for UI action not working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 03:06 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 10:06 PM
Hi @Shubham Gagneja following are some finding in your script:
- gs.info Doesn't Work in Client-Side Scripts and ensure that g_aw is properly loaded.
- Ensure sysparm_name in GlideAjax Matches the Server Function Your GlideAjax call uses: ContactCall.addParam("sysparm_name", "findContact"); and Script Include function is: findContact: function(ContactNum).
Use below updated UI Action script for your reference:
function runClientSideCode() {
g_form.addInfoMessage("Search button clicked!");
var tableName = "x_ccn_contact";
var contactNumber = g_form.getValue("contact_number");
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); // Fix parameter name
ContactCall.getXMLAnswer(function(response) {
console.log("GlideAjax Response: ", response);
if (response) {
var ContactSysId = response;
console.log("Contact sys_id: ", ContactSysId);
if (ContactSysId) {
g_navigation.openRecord(tableName, ContactSysId); // Open contact profile in workspace
} else {
g_form.addErrorMessage("Contact not found.");
}
} else {
g_form.addErrorMessage("Error in GlideAjax call.");
}
});
}
Script Include
var ContactSearchAjax = Class.create();
ContactSearchAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
findContact: function() {
var ContactNum = this.getParameter("sysparm_ContactNum"); // Fix parameter name
var gr = new GlideRecord("x_ccn_contact");
gr.addQuery("contact_number", ContactNum);
gr.query();
if (gr.next()) {
return gr.getValue("sys_id");
}
return "";
}
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2025 08:00 AM
Hey Nilesh, Thanks for getting back. I believe g_navigation is for ui action client script but now for WOrkspace script. I tried it didn;t work!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2025 08:29 AM
Server Code Verification: You need to verify that the GlideRecord is returning data correctly and that the findContact function on the server is working with the request.