Client callable Script Include returning null to UI Action

davilu
Mega Sage

Hello experts, I can't figure what I'm doing wrong.  I have a UI Action that calls a Script Include.  When I log my Script Include, I'm seeing the correct value returning, but when I set up alerts in my UI Action, the alerts are returning null.

 

Script Include method:

closeTask: function() {
        var tblName = this.getParameter("sysparm_table_name");
        var sysId = this.getParameter("sysparm_sys_id");
        var newNote = this.getParameter("sysparm_new_note");

        this.closeHRTaskWithComment(tblName, sysId, newNote);
    },
 closeHRTaskWithComment: function(table, uniqueID, comment) {

        var response = {};
        var hrTaskGR = new GlideRecord(table);

        if (hrTaskGR.get(uniqueID)) {
            if (hrTaskGR.canWrite()) {
                this._updateNotes(hrTaskGR, comment, false);
                this._workEnd(hrTaskGR);

                hrTaskGR.state = hr.STATE_CLOSE_COMPLETE;
                response.success = hrTaskGR.update() ? true : false;
            } else
                response.error = 'No write access to record.';
        } else 
            response.error = 'Record not found.';
	        gs.info('dlu ' + JSON.stringify(response))
        return JSON.stringify(response);
    },

When I check the logs, I see this:

davilu_0-1731104165101.png

 

My Workspace UI Action looks like this:

function onClick(g_form) {
    getMessages(['Work Notes', 'Provide a summary of the work performed'], function() {
        var sysId = typeof rowSysId == 'undefined' || rowSysId == null ? g_form.getUniqueValue() : rowSysId;
        //Setup the fields for modal
        var fields = [{
            type: 'textarea',
            name: 'work_notes',
            label: getMessage('Work Notes'),
            mandatory: true
        }];
        //Create the modal	
        g_modal.showFields({
            title: getMessage('Provide a summary of the work performed'),
            fields: fields,
            size: 'md'
        }).then(function(fieldValues) {
            //Get the new worknote
            var newWorkNote = fieldValues.updatedFields[0].value;
            //Call to GlideAjax to close the task
            var gA = new GlideAjax("sn_hr_core.hr_CaseAjax");
            gA.addParam("sysparm_name", "closeTask");
            gA.addParam("sysparm_table_name", g_form.getTableName());
            gA.addParam("sysparm_sys_id", g_form.getUniqueValue());
            gA.addParam("sysparm_new_note", newWorkNote);
            gA.getXML(saveForm);

            function saveForm(response) {
                var answer = response.responseXML.documentElement.getAttribute("answer");
                answer = JSON.parse(answer);
                alert('here? ' + answer)

                g_form.save().then(function() {
                    //g_aw.closeRecord();
                });
            }
        });
    });
}

 

My alert returns null:

davilu_1-1731104261571.png

Any idea what I'm missing?

 

 

6 REPLIES 6

Hello @davilu 

Try to debug by

  • returning the hard-coded value from script include and check if the data is passed to ui action.
  • Use getXMLAnswer method 
  • Add logs/alert at multiple places to debug 

Thank you 

Juhi Poddar 

Hello @davilu 

 

Add console.log(response.responseXML.documentElement); in the saveForm function 

 

function saveForm(response) {
		console.log(response.responseXML.documentElement);
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);

        if (answer) { // Check if answer is not null or empty
            try {
                answer = JSON.parse(answer); // Parse if answer is valid JSON
				alert(answer.success);
            } catch (e) {
                console.error("Parsing error: ", e);
            }
        } else {
            console.warn("No answer attribute found or attribute is empty.");
        }
    }

 

Check in console window if the attribute name is 'answer' and the value it holds.

JuhiPoddar_0-1731222946958.png

 

"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