Getting Invalid update on BR

nishakumari1
Tera Contributor
Requirement is : when reassignment count is more than 3. make work notes mandatory. 
 
Below is the BR
 
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var previouscount = previous.reassignment_count;
if (current.work_notes.nil()&&current.comments.nil()) {
    //gs.addInfoMessage(previouscount);
   // gs.addErrorMessage('Please enter comments when changing assignment group for incidents with reassignment count greater than 3.');
gs.addInfoMessage('Please enter comments when changing assignment group for incidents with reassignment count greater than 3.');
    current.setAbortAction(true);
    current.reassignment_count = previouscount;

}

})(current, previous);
 
On execution of the BR getting Invalid Update message. Please Guide me on this.
1 ACCEPTED SOLUTION

@Bjarne Nielsen completely agree 😉

 

CS + GlideAjax can get this one working.

Sample:

Client Script

function onLoad() {
    var ga = new GlideAjax('MyIncidentUtils');
    ga.addParam('sysparm_name', 'getReassignmentCount');
    ga.addParam('sysparm_incidentID', g_form.getUniqueValue());
    ga.getXMLAnswer(formLogic);

    function formLogic(answer) {
        var reassignmentCount = parseInt(answer);
        g_form.addInfoMessage('Reassignment count: ' + reassignmentCount);
        if (reassignmentCount > 2) {
            g_form.addInfoMessage("Count is above 2 - make work_notes mandatory");
            g_form.setMandatory("work_notes", true);
        } else {
            g_form.addInfoMessage("Count is 2 or less - do nothing");
        }
    }
}

 

Script Include

var MyIncidentUtils = Class.create();
MyIncidentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getReassignmentCount: function() {
        var incident = this.getParameter('sysparm_incidentID');
        var gIncident = new GlideRecord('incident');
        gIncident.get(incident);
        return gIncident.reassignment_count;
    },
    type: 'MyIncidentUtils'
});

View solution in original post

7 REPLIES 7

Bert_c1
Kilo Patron

That is expected, with 'current.setAbortAction(true)'. The update is invalid based on your logic. the info message explains that.

Community Alums
Not applicable

Hi @nishakumari1 ,

 

Since you are using  current.setAbortAction(true);, it will show 'Invalid update'. But from your code above, you don't need to update count to the previous one because you already stop the execution.

 

Try below BR with "Before - Update, Condition is 'Assignment group' changes"

 

Script:

 

 

if (current.reassignment_count > 3 && current.work_notes.nil()) { // you can add Comment if you want
        gs.addErrorMessage('Please enter comments when changing assignment group for incidents with reassignment count greater than 3.');
        current.setAbortAction(true);
        action.setRedirectURL(current);
    }

 

Bjarne Nielsen
Tera Expert

Business Rule would not be my approach.
It is not user friendly, since it does not guide the user before submitting the form, and it also can interfere with automatic updates that might be relevant.

Instead I would use a Client Scipt to set Work Notes as Mandatory in the specified scenario.

@Bjarne Nielsen completely agree 😉

 

CS + GlideAjax can get this one working.

Sample:

Client Script

function onLoad() {
    var ga = new GlideAjax('MyIncidentUtils');
    ga.addParam('sysparm_name', 'getReassignmentCount');
    ga.addParam('sysparm_incidentID', g_form.getUniqueValue());
    ga.getXMLAnswer(formLogic);

    function formLogic(answer) {
        var reassignmentCount = parseInt(answer);
        g_form.addInfoMessage('Reassignment count: ' + reassignmentCount);
        if (reassignmentCount > 2) {
            g_form.addInfoMessage("Count is above 2 - make work_notes mandatory");
            g_form.setMandatory("work_notes", true);
        } else {
            g_form.addInfoMessage("Count is 2 or less - do nothing");
        }
    }
}

 

Script Include

var MyIncidentUtils = Class.create();
MyIncidentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getReassignmentCount: function() {
        var incident = this.getParameter('sysparm_incidentID');
        var gIncident = new GlideRecord('incident');
        gIncident.get(incident);
        return gIncident.reassignment_count;
    },
    type: 'MyIncidentUtils'
});