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

Sid_Takali
Kilo Patron
Kilo Patron

Hi @divyal09 Try below code

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

The data in expiring date field is not getting updated.

FidelFernandez
Tera Contributor

I think my partner's  Sid_Takali script is the correct one, have you been able to test it?

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

})(current, previous);


If it doesn't work, try the following one, which is very similar. Best regards

I tried but data is not updating in the field