Unable to get previous value using BR

Karishma Dubey
Tera Expert

Hello,

I am trying to perform some actions based on new value and previous value of BU code field present on user table.

I created after(update on some field value change) BR on user table and writing below code. However I am getting blank value in logs. Please suggest.

 

if (current.u_sf_business_unit_code.changes()) {
var prevBU = previous.u_sf_business_unit_code;
var newBU = current.u_sf_business_unit_code;
gs.log('previous BU', prevBU);
gs.log('newBU ', newBU);
try {
gs.log('BU changes ');
sn_fd.FlowAPI.getRunner().subflow('global.sml_internal_mover__business_unit').inBackground().withInputs(inputs).run();

} catch (ex) {
var message1 = ex.getMessage();
gs.error(message);
}

}

11 REPLIES 11

I made it before BR. however it is still returning me blank.

Please comment the first if loop and and check what the previous object contains by adding a infomessage.

Deborah Brown L
Kilo Sage

In After Business Rule, Previous value will be blank because the value is already updated in the database which means it is the current value.

Aman Kumar S
Kilo Patron

Hi  @Karishma Dubey 

Can you share screenshot of your BR, your user table field on the form and how the logs look like.

Best Regards
Aman Kumar

Not applicable

Hi @Karishma Dubey 

 

Can you try this and help me with the logs-

 

if (current.u_sf_business_unit_code.changes()) {
    var prevBU = previous.u_sf_business_unit_code;
    var newBU = current.u_sf_business_unit_code;
    gs.log('Previous BU: ' + prevBU);
    gs.log('New BU: ' + newBU);
    try {
        gs.log('BU changes detected, initiating subflow.');
        var inputs = {}; // Define and populate your inputs object here
        sn_fd.FlowAPI.getRunner().subflow('global.sml_internal_mover__business_unit').inBackground().withInputs(inputs).run();
    } catch (ex) {
        var message = ex.getMessage();
        gs.error(message);
    }
}

Please mark it helpful and correct if it works.

 

Regards,

Amit