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

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

Community Alums
Not applicable

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

 

inc.PNG

 

 

work.PNG

 

Regards

Suman P.