- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 11:35 AM
Hi Community,
I have tried many times to call script includes from client-side UI actions to fetch some data from server side. It never works and always give me error on the browser console:
In the Client-side UI actions, use g_modal to show fields on the pop up window, there's a choice field whose options are dynamically fetched using the GlideAjax to call a script include to fetch the data. The g_modal shows but can't fetch any data from the server side.
The UI action Workspace Client Script:
function onClick(g_form) {
g_modal.showFields({
title: "Recommendation",
fields: [{
type: 'choice',
name: 'recommendation',
label: 'Choose your recommendation here. If your recommendation is not listed, please add your own recommendation',
choice: getRecommendations(),
mandatory: true
},
{
type: 'textarea',
name: 'comments',
label: getMessage('Please add close comment here'),
mandatory: true
}
],
size: 'lg'
}).then(function(fieldValues) {
g_form.setValue('work_notes', "Recommendation: " + fieldValues.recommendation);
g_form.setValue('comments', fieldValues.comments);
g_form.setValue('sub_state', 6); // set sub state to recommendated by preliminary analysis
g_form.setValue('state', 3); // Set state to closed
g_form.save();
});
}
function getRecommendations() {
var pr_case = g_form.getValue('pr_case');
var ga = new GlideAjax('<the full API Name of the script include');
ga.addParam('sysparm_name', 'getRecommendations');
ga.addParam('sysparm_pr_case', pr_case);
ga.getXMLAnswer(function(response) {
var recommendations = JSON.parse(response);
if (recommendations.length === 0) {
alert("no recommendations");
return;
}
// Create dropdown options for recommendations
var options = recommendations.map(function(rec) {
return {
displayValue: rec.recommendation,
value: rec.sys_id
};
});
});
}
The script include function:
getRecommendations: function() {
var prCaseId = this.getParameter('sysparm_pr_case'); // Get PR Case value from Case Task
var recommendations = [];
var recGR = new GlideRecord('<recommendation table name>'); // Recommendation table
recGR.addQuery('case', prCaseId); // Match recommendation's 'case' field with case task's 'pr_case'
recGR.query();
while (recGR.next()) {
recommendations.push({
sys_id: recGR.getUniqueValue(),
recommendation: recGR.getValue('recommendation')
});
}
return JSON.stringify(recommendations); // Return as JSON
},
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 12:16 PM
Hi @ShuRiseUp2023,
Please switch the order, first do GlideAjax to get recommendations, and in the callback function, display the modal.
function onClick(g_form) {
var pr_case = g_form.getValue('pr_case');
var ga = new GlideAjax('<the full API Name of the script include');
ga.addParam('sysparm_name', 'getRecommendations');
ga.addParam('sysparm_pr_case', pr_case);
ga.getXML(displayModal);
}
function displayModal(response) {
var options;
var recommendations = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
if (recommendations.length === 0) {
alert("no recommendations");
}
// Create dropdown options for recommendations
options = recommendations.map(function(rec) {
return {
displayValue: rec.recommendation,
value: rec.sys_id
};
});
g_modal.showFields({
title: "Recommendation",
fields: [{
type: 'choice',
name: 'recommendation',
label: 'Choose your recommendation here. If your recommendation is not listed, please add your own recommendation',
choice: options,
mandatory: true
},
{
type: 'textarea',
name: 'comments',
label: getMessage('Please add close comment here'),
mandatory: true
}
],
size: 'lg'
}).then(function(fieldValues) {
g_form.setValue('work_notes', "Recommendation: " + fieldValues.recommendation);
g_form.setValue('comments', fieldValues.comments);
g_form.setValue('sub_state', 6); // set sub state to recommendated by preliminary analysis
g_form.setValue('state', 3); // Set state to closed
g_form.save();
});
}Please test it and let me know if it works or if it throw an error message with screenshots to assist further on this,
Thanks & Best regards,
Medi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 11:41 AM
Is the Script Include Client callable? Do the first two lines extend the AjaxProcessor object?
var AccountUtils = Class.create();
AccountUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 11:48 AM - edited 03-11-2025 11:56 AM
yes. It's in a scoped application, not Global scope. It always gives me POST 404 Not found error as shown in the post.
var GetRecommendationsForCase= Class.create();
GetRecommendationsForCase.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
initialize: function() {},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 12:02 PM
I don't know if this matters, but Client callable scripts don't have the initialize function. Are you using the full API Name in the GlideAjax call? Is the Caller Access -- None -- and Accessible from All application scopes?
var ga = new GlideAjax('sn_bom.BankingQueryAjax');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 08:13 AM
Yes. I used the full API Name in the GlideAjax call. set it as you described. Removed the initialize function. but still not working.
