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

thank you so much.. it worked for me

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @nishakumari1 

 

You can use UI policy and also , you need to update Save UI action to make it mandatory before page load.

 

@Anurag Tripathi 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Amit Gujarathi
Giga Sage
Giga Sage

HI @nishakumari1 ,
I trust you are doing great.

 

Here's a revised version of your script:

(function executeRule(current, previous /*null when async*/) {
    // Check if the reassignment count is greater than 3
    if (current.reassignment_count > 3) {
        // Check if both work notes and comments are empty
        if (current.work_notes.nil() && current.comments.nil()) {
            // Inform the user that work notes or comments are required
            gs.addErrorMessage('Please enter work notes or comments when changing the assignment group for incidents with a reassignment count greater than 3.');
            // Abort the update to enforce adding notes or comments
            current.setAbortAction(true);
        }
    }
})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi