How can we configure Business Rule so that the data in expiring date field gets updated on template

divyal09
Tera Contributor

I have added a field as Expiring date(u_expiring_date) on a standard change proposal (std_change_proposal) whenever a request is submitted to modify or create a change template expiring date field is getting updated on Standard Change Proposal (std_change_proposal), how can we configure Business Rule so that the data in expiring date field gets updated on Standard Change template (std_change_record_producer).

Business Rule I have written on std_change_proposal table :

 

(function executeRule(current, previous /*null when async*/ ) {

    var c = current.current_version;
    var recordp = new GlideRecord('std_change_record_producer');
    recordp.addQuery('sys_id', c);
    recordp.query();
    if (recordp.next()) {
        recordp.u_expiring_date = current.u_expiring_date;
        recordp.update();
    }

})(current, previous);

 

6 REPLIES 6

try to enter some logs at each step and check where it gets stuck and if it takes the data in the variables correctly. If it doesn't work, let us know and we'll try it on a test instance.

Community Alums
Not applicable

Hi @divyal09 ,

Please make sure your BR is before and add below script

(function executeRule(current, previous /*null when async*/ ) {
    if (current.current_version) {
        var recordp = new GlideRecord('std_change_record_producer');
        recordp.addQuery('sys_id', current.getValue("current_version"));
        recordp.query();
        if (recordp.next()) {

            var gd = new GlideDateTime("current.u_expiring_date");
            recordp.u_expiring_date = gd;
            gs.log("Inside if = " + gd) // Check in logs table for this log
            recordp.update();
        }
    }
})(current, previous);

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak