Comments/work notes getting updated twice after changing the stage and state using UI action

Pradeep Patel1
Tera Contributor

I have created button for changing the state to close incomplete and also change stage to request cancelled

 

following is the script

 

function confirmCancellationNew() {
    var msg = '';
    var flag = confirm('Cancelling a Request Item cannot be undone' + msg + ', would you like to proceed?');

    if (flag == true) {
        g_form.checkMandatory = false;
        try {
            //now ignore any mandatory variables

            var allVariables = document.getElementById('variable_map').getElementsByTagName('item');
            for (var i = 0; i < allVariables.length; i++) {
                var item = allVariables[i];
                g_form.setMandatory('variables.' + item.getAttribute('qname').toString(), false);
            }
        } catch (err) {}
        gsftSubmit(null, g_form.getFormElement(), 'cancel_request_item_new');
    } else
        return false;
}
if (typeof window == 'undefined') {
    cancelRequestItemNew();
}

function cancelRequestItemNew() {

    current.comments = "Request was cancelled by " + gs.getUserDisplayName();
    new Workflow().cancel(current);

    current.u_cancel_flag = true;

    current.stage = 'Request Cancelled';
    current.state = '4';
    current.approval = 'no_approval_required';
    current.update();

    new UIActionUtils().approvalsNoLongerRequired(current.sys_id); //Script Include to cancel approvals if any

    action.setRedirectURL(current);

    cancelSCTasks();
}

function cancelSCTasks() {

    var grTASK = new GlideRecord('sc_task');
    grTASK.addQuery('request_item', current.sys_id);
    grTASK.addActiveQuery();
    grTASK.query();
    while (grTASK.next()) {

        grTASK.state = '4';
        grTASK.active = 'false';
        grTASK.update();
    }
}
action.setRedirectURL(current);
 
already tried using setworkflow false, which stops updating comments once also, if writing before current.update
and it updates twice if written after current.update,  all other script already checked which are used here in the code, they does not update work notes, this is something running ootb? please help me in this
 
they only comment I am doing is highlighted in yellow, which is repeating once.
 
 
PradeepPatel1_0-1721209875741.png

 

2 REPLIES 2

Priscilla Muiua
ServiceNow Employee
ServiceNow Employee

Hello,

 

This is a question for the ITSM team. Please post this on their community site 

https://www.servicenow.com/community/itsm/ct-p/it-service-management to get your question answered.

 

Thank you,

Priscilla

Sumanth16
Kilo Patron