<= condition for today in BR

Poorva Bhawsar
Mega Sage

How to write a <= today condition in a BR.

 

So, last bia approval is a date field. In this BR, i need to check that if last bia approval is not empty and last bia approval is <= today or > today.

 

Is this the correct way to write this for a date field.

if(current.u_last_bia_approval != '' && current.u_last_bia_approval <= 'today'){
        current.setValue('u_bia_state', 'Expired BIA');
8 REPLIES 8

Yashsvi
Kilo Sage

Hi @Poorva Bhawsar,

please try below script:

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

    // Get the current date
    var currentDate = new GlideDateTime();
    
    // Check if the last bia approval field is not empty
    if (!current.u_last_bia_approval.nil()) {
        // Convert the last bia approval date to GlideDateTime for comparison
        var lastBiaApprovalDate = new GlideDateTime(current.u_last_bia_approval);
        
        // Compare dates
        if (lastBiaApprovalDate <= currentDate) {
            current.setValue('u_bia_state', 'Expired BIA');
        } else {
            current.setValue('u_bia_state', 'Valid BIA');
        }
    }

})(current, previous);

Thank you, please make helpful if you accept the solution.

So, here is my complete BR, let me know if anything needs to be corrected.

 

var currentDate = new GlideDateTime();

        if (!current.u_last_bia_approval.nil()) {
            // Convert the last bia approval date to GlideDateTime for comparison
            var lastBiaApprovalDate = new GlideDateTime(current.u_last_bia_approval);

        }
        if (current.u_last_bia_approval != '' && lastBiaApprovalDate <= currentDate) {
            current.setValue('u_bia_state', 'Expired BIA');
        }
        else if (current.u_last_bia_approval != '' && lastBiaApprovalDate > currentDate) {
            current.setValue('u_bia_state', 'Published BIA');
        }
        else if(current.u_last_bia_approval == '') {
            current.setValue('u_bia_state', 'No Published BIA');
        }

Hi @Poorva Bhawsar,

No , try this script.

Thank you, please make helpful if you accept the solution.

But mainly i have 3 conditions:

1. if last bia approval is empty.

2. if last bia approval is not empty and <= today.

3. if last bia approval is not empty and > today.