- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 08:42 AM
Hi,
I have a requirement to show the incidents selected in slush bucket to be populated under Work Notes. I have written clientScript and GlideAjax and it is showing in the alert, but not populating in the work notes. Kindly help.
GlideAjax
function onSubmit() {
//Type appropriate comment here, and begin script below
var inc = g_form.getValue("incidents_submitted_by_itam");
var ga = new GlideAjax("listCollectorIncidentClass");
ga.addParam("sysparm_name", "listCollectorIncidentFunction");
ga.addParam("sysparm_id", inc);
ga.getXML(callBackFuntion);
function callBackFuntion(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var ans = answer.split(",");
for (var i = 0; i < ans.length; i++) {
alert("this is alert" + ans[i]);
g_form.setValue("work_notes", ans[i]);
}
}
}
ScriptIncludes
var listCollectorIncidentClass = Class.create();
listCollectorIncidentClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
listCollectorIncidentFunction: function() {
var incArr = this.getParameter('sysparm_id').toString().split(',');
var numArr = [];
for (var i = 0; i < incArr.length; i++) {
var inc1 = new GlideRecord('incident');
if (inc1.get(incArr[i].toString())) {
numArr.push(inc1.number);
}
}
gs.log("Test for Suman", numArr);
var answer = numArr.join(',');
return answer;
// return JSON.stringify(numArr);
},
type: 'listCollectorIncidentClass'
});
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 10:31 AM
Hi @Community Alums
Use getXMLWait() instead of getXML, as asynchronous call will not work on onSubmit
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 10:31 AM
Hi @Community Alums
Use getXMLWait() instead of getXML, as asynchronous call will not work on onSubmit
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 11:02 AM - edited 09-29-2023 11:04 AM
Hi @Vishal Birajdar ,
I have modified the script from google, and I am able to see the incident. Until a while I thought it will be under work_notes field, but it is under activities. Thank you for helping me
function onSubmit() {
//Type appropriate comment here, and begin script below
var inc = g_form.getValue("incidents_submitted_by_itam");
var ga = new GlideAjax("listCollectorIncidentClass");
ga.addParam("sysparm_name", "listCollectorIncidentFunction");
ga.addParam("sysparm_id", inc);
ga.getXMLWait();
var answer = ga.getAnswer();
g_form.setValue("work_notes", answer);
// g_form.work_notes = answer;
}
Regards
Suman P.