- 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 08:46 AM
Hi @Community Alums
Do you want to show list of incidents in work notes of RITM...??
If so then you can use workflow/flow designer to update worknotes.
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 09:47 AM - edited 09-29-2023 09:48 AM
Hi @Vishal Birajdar,
The incidents I select in Slush Bucket at the task level, should only be shown in Work Notes at the task level. I am currently able to get the incidents list in the alert.
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 10:01 AM
Hi @Community Alums
You can put variable attribute to list collector variable as below screenshot, it will be better to visualise.
In onSubmit, try to put set worknotes directly no need of for loop.
g_form.work_notes = answer;
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:20 AM - edited 09-29-2023 10:24 AM
Hi @Vishal Birajdar ,
I tried both the ways. Work Notes is still empty.
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");
alert(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]);
// }
g_form.setValue("work_notes", answer); //tried commenting this
g_form.work_notes = answer; //alternatively tried commenting this
}
}