Business Rule script to populate the date/time on field incident table level.

LaraReddy
Tera Guru

HI,

When we set the state to on hold and on hold reason field to any one option, then we want to populate the date/time on "On Release" field level.

During the process, when we change the on hold reason field to any other options without changing the state from on hold then we don't want to change the populated date/time.

And the populated the time should change only when we change the state from on hold.

We wrote the below business rule to run when state changes to on hold and it's working fine.

Now the requirement is we don't want to populate date/time when the "on hold reason" field option is either A or C.

Can anyone please help us to adjust the below script to skip the date/time.

(function executeRule(current, previous /*null when async*/ ) {
//functionality configurations
var tz = "America/New_York"; 
var hours = 48;
var rightNow = new GlideDateTime();
var dur = new GlideDuration(3600000 * hours); 

var schedule = new GlideSchedule('021479371bdb99d04649c845604bcb58', tz);
var releaseDT = schedule.add(rightNow, dur);
current.u_hold_release = releaseDT;

})(current, previous);


Thanks,
LARA REDDY




1 ACCEPTED SOLUTION

HI Lara,
Hope the below script helps you.



(function executeRule(current, previous /*null when async*/ ) {
    //functionality configurations
    var tz = "America/New_York";
    var hours = 48;
    var rightNow = new GlideDateTime();
    var dur = new GlideDuration(3600000 * hours);


    var popsTime = current.u_capture_time; // getting the pre populated data

    // if the hold reason is problem or change , clearing the populated data

    if ((current.hold_reason == '3' || current.hold_reason == '5') && (!previous.u_hold_release.nil())) {
        gs.addErrorMessage('three');
        current.u_hold_release = '';
    }
    // state is still on hold and on hold field changes to some other options then populating the existing date/time.
    else if ((current.state == previous.state) && (current.hold_reason == '1' || current.hold_reason == '2' || current.hold_reason == '4') && (!current.u_capture_time.nil())) {
        gs.addErrorMessage('one');
        current.u_hold_release = popsTime;
    }

    // state is on hold and on hold is any one option we are setting the future date/time in on release field level.
    else if ((current.state == '3') && (current.hold_reason == '1' || current.hold_reason == '2' || current.hold_reason == '4') && (current.u_capture_time.nil())) {
        gs.addErrorMessage('two');
        var schedule = new GlideSchedule('021479371bdb99d04649c845604bcb58', tz);
        var releaseDT = schedule.add(rightNow, dur);
        current.u_hold_release = releaseDT;
        current.u_capture_time = releaseDT;
    }
})(current, previous);

 
Thanks,
AR

View solution in original post

10 REPLIES 10

Utpal Dutta
Tera Guru

Hi Lara,

Why don't you make use of Condition field available under advance option in BR form. In condition field you can check the current value of any field if it only matches then only the below script will run. 

 

You can write something like below in condition:

current.on_hold_reason !="a" || current.on_hold_reason != "c"

 

If my answer helps then please mark it correct.

 

Thanks,

Utpal

Hi Utpal,
Many thanks for the response.

We tried the above logic but no luck.


Example:
1. State is On hold && on hold reason is B =     2023-11-08 04:35:25  [date/time is populated]
2. State is still same && on hold reason is changed to A ==  On Reason field populated date/time is cleared
3. And now still state is same and on hold reason is changes to B or D == We need to set the first populated date/time [2023-11-08 04:35:25] again because we're not changed the state from on hold.


I hope you got my requirement/issue.

Thanks,
LARA Reddy

Hi @LaraReddy ,

You probably can use another field to temporarily save the value of On Release, then populate to value back to On Release as needed.

LaraReddy
Tera Guru

Hi @Ankur Bawiskar ,
Could you please us here.

Thanks,
LARA