HR Case Cancel U Action Customization

heathers_
Kilo Sage

I've made a copy of the "Cancel" UI Action on sn_hr_core_case (HR Agent Workspace.) I've also copied the script include to modify with my custom fields. I'd like to customize the popup to display a reference field instead of the work notes. Everything appears to have worked except the results in the reference field are not displaying.

I've updated the type, name and label. Is there something I'm missing?

heathers__0-1712133299911.png

 

 

function onClick(g_form) {
	getMessages(['Canceled Reason', 'Cancel Case', 'Provide a reason for canceling the case.', 'Enter a reason for canceling', 'This action can\'t be undone.', 'Don\'t cancel', 'Cancel case'], function(){
		var fields = [{
			type: 'reference',
			name: 'u_canceled_reason',
			label: getMessage('Canceled Reason')
		}];

		var sysId = g_form.getUniqueValue();
		var tblName = g_form.getTableName();

		g_modal.showFields({
			title: getMessage('Enter a reason for canceling'),
			fields: fields,
			instruction: getMessage('This action can\'t be undone.'),
			size: 'md',
			cancelTitle: getMessage('Don\'t cancel'),
			confirmTitle: getMessage('Cancel case'),
			cancelStyle: 'default',
			confirmStyle: 'destructive'
		}).then(function(fieldValues) {
			//get the work note entered
			var cancelReason = fieldValues.updatedFields[0].value;
			//Call the Ajax function that handles adding worknotes and state
			var s = new GlideAjax("sn_hr_core.hr_CancelAjax");
			s.addParam("sysparm_name", "cancelAction");
			s.addParam("sysparm_obj_id", sysId);
			s.addParam("sysparm_table_name", tblName);
			s.addParam("sysparm_u_canceled_reason", cancelReason);
			s.getXML(addNotes);

			function addNotes(response) {
				g_form.save();
			}
		});
	});
}

 

Missing results

heathers__1-1712133300060.png

 

 

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @heathers_ 

Let's give my adjustment below a try.

var fields = [];
fields.push({
	type: 'reference',
	name: 'u_canceled_reason',
	label: "getMessage('Canceled Reason')",
	mandatory: true,
	reference: '<your_reason_table>',
	referringTable: 'sn_hr_core_case',
	referringRecordId: g_form.getUniqueValue()
});

 

Cheers,

Tai Vu

View solution in original post

5 REPLIES 5

Tai Vu
Kilo Patron
Kilo Patron

Hi @heathers_ 

Let's give my adjustment below a try.

var fields = [];
fields.push({
	type: 'reference',
	name: 'u_canceled_reason',
	label: "getMessage('Canceled Reason')",
	mandatory: true,
	reference: '<your_reason_table>',
	referringTable: 'sn_hr_core_case',
	referringRecordId: g_form.getUniqueValue()
});

 

Cheers,

Tai Vu

@Tai Vu this was very helpful!

 

The values displayed, however they did not map to the field on the case. It appears the sys_id for the value selected is writing to the work notes.

Hi @heathers_ 

There you go. Replace this line below in your code.

From

var cancelReason = fieldValues.updatedFields[0].value;

To

var cancelReason = fieldValues.updatedFields[0].displayValue;

 

Cheers,

Tai Vu 

Could it be mapping in the script include? Specifically this line "

this._updateNotes(grCase, cancelReason, false);"

 

cancelAction: function() {
        //gets the parameters passed in by the UI Action
        var objSysId = this.getParameter('sysparm_obj_id');
        var tblName = this.getParameter('sysparm_table_name');
        var cancelReason = this.getParameter('sysparm_u_canceled_reason');
        //opens the record 
        var grCase = new GlideRecord(tblName);
        if (grCase.get(objSysId) && grCase.canWrite()) {
            //updates the worknotes and state fields
            this._updateNotes(grCase, cancelReason, false);
            grCase.state = hr.STATE_CANCEL;
            grCase.update();
        }
    },