The CreatorCon Call for Content is officially open! Get started here.

Work notes is not updating in UI action in server-side script.

Mohan raj
Mega Sage

Hi,
I have a requirement to create a UI action in problem table i.e., Cancel Button

If user Click on cancel button, then problem record should closed and problem task which is associated with current problem should closed. Cancel reason should updated in worknotes of problem task but it try different method to update work notes in problem task it not working.

 

function onModalCancel() {

    var reason = prompt('Enter the reason why you want to cancel the problem?');
    var sysID = g_form.getUniqueValue();
    if (ques) {
        g_form.setValue('state', 107); //cancel
        g_form.setValue('resolution_code', 'canceled');
        g_form.setValue('close_notes', reason);
// 		g_form.setValue('work_notes',ques);
        g_form.save();
        gsftSubmit(null, g_form.getFormElement(), 'sysverb_modal_cancel');
    }
}


function cancelProblemTask() {
    var prb_task = new GlideRecord('problem_task');
    prb_task.addQuery('problem', sysID);
    prb_task.query();
    while (prb_task.next()) {
		prb_task.work_notes = reason;
        prb_task.state = 157; //closed
		
        prb_task.update();  
    }

	action.setRedirectURL(current);
}

 

 

Regards

Mohan

6 REPLIES 6

DB1
Tera Contributor

Hi Mohan, Please try the following

prb_task.work_notes.setJournalEntry(reason);

Hi @DB1 ,
I try this method as well but still worknotes is not updating in problem_task table

try another method

prb_task['work_notes'].setJounralEntry(reason);

 

Both methods are not working 

DB1
Tera Contributor

You have added variables inside a different function. It has to be set global so that it can be accessed from other functions too.

 

Try adding the variables above the function

as

 

  var reason = prompt('Enter the reason why you want to cancel the problem?');
    var sysID = g_form.getUniqueValue();
function onModalCancel() {

  

or you may have to add those 2 variables again in cancelprobelmtask() function too

 

function cancelProblemTask() {
var reason = prompt('Enter the reason why you want to cancel the problem?');
var sysID = g_form.getUniqueValue();

}

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Mohan raj 

your script is wrong.

please update as this

function onModalCancel() {

	var reason = prompt('Enter the reason why you want to cancel the problem?');
	if (reason != '') {
		g_form.setValue('close_notes', reason);
		gsftSubmit(null, g_form.getFormElement(), 'sysverb_modal_cancel');
	}
}

//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
	cancelProblemTask();

function cancelProblemTask() {

	var prb_task = new GlideRecord('problem_task');
	prb_task.addQuery('problem', current.sys_id);
	prb_task.query();
	while (prb_task.next()) {
		prb_task.work_notes = reason;
		prb_task.state = 157; //closed
		prb_task.update();  
	}

	current.setValue('state', 107); //cancel
	current.setValue('resolution_code', 'canceled');
	current.update();
	action.setRedirectURL(current);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader