Incident list collector values should be shown in Work Notes at the fulfillment

Community Alums
Not applicable

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]);
        }
	}
}

 

CatalogClientScript.PNG

 

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'
            });

 

ScriptInclude_1.PNG

 

WorkNotes.PNG

 

Regards

Suman P.

 

1 ACCEPTED SOLUTION

Hi @Community Alums 

Use getXMLWait() instead of getXML, as asynchronous call will not work on onSubmit 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

6 REPLIES 6

Vishal Birajdar
Giga Sage

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.

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Community Alums
Not applicable

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.

 

shoul.PNG

 

Regards

Suman P.

Hi @Community Alums 

 

You can put variable attribute to list collector variable as below screenshot, it will be better to visualise.

 

VishalBirajdar_0-1696006399985.png

 

 

In onSubmit, try to put set worknotes directly no need of for loop.

 

g_form.work_notes = answer;

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Community Alums
Not applicable

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
    }
}

 

 

 

inc.PNG

 

alert.PNG

 

work.PNG