Getting the value as object object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 01:15 AM - edited 11-13-2024 01:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 01:35 AM
Hello @JPSS ,
In your script include return statement should be as below
return JSON.stringify(category_arr);
Thanks,
Valmik Patil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 02:57 AM
still getting the same error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 03:38 AM
Hello @JPSS ,
Instead of getXML could you try getXMLAnswer
And Try to print answer as
alert(answer[0]);
Thanks,
Valmik Patil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 05:14 AM
Hello @JPSS
- The issue is in client script "sap.getXML(categorycallback)".
- Also add try catch to handle the error.
- Please try the below updated client script and script include.
Updated client script:
function onLoad() {
var sap = new GlideAjax('ProcessTraining');
sap.addParam('sysparm_name', 'closecategory');
sap.getXMLAnswer(categoryCallback);
function categoryCallback(answer) {
try {
var response = answer.split(","); // Or JSON.parse(answer) if returning JSON format
g_form.addInfoMessage("Categories: " + response.join(", "));
} catch (e) {
console.error("Error parsing response: ", e);
g_form.addErrorMessage("Failed to retrieve categories.");
}
}
}
Script include:
var ProcessTraining = Class.create();
ProcessTraining.prototype = Object.extendsObject(AbstractAjaxProcessor, {
closecategory: function() {
var category_arr = [];
var category = new GlideRecord("u_choice_list");
// Adjust query to target correct criteria
category.addEncodedQuery("u_type=service_catalog^u_parent.u_parent.u_choice_value=Tech^u_parent.u_choice_value=HR");
category.query();
while (category.next()) {
// Push the sys_id as a string into the array
category_arr.push(category.sys_id.toString());
}
// Return the array as a comma-separated string (or JSON format if needed)
return category_arr.toString(); // or JSON.stringify(category_arr) for JSON format
},
type: 'ProcessTraining'
});
I hope this resolves your query!
"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar