Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

To Revert a Field to Its Original Value

raksh
Tera Contributor

Hi All

I have a requirement and would really appreciate any help or guidance.

The issue I am facing is with Scenario 2.
For example, if the original Case Type is Incident:
Assignment Group satisfies all 3 criteria → Case Type changes from Incident to Apple. The Assignment Group is later changed to a group that does not satisfy the 3 criteria. At this point, I want the Case Type to revert from Apple back to Incident but this not happening.
Since the original Case Type can be any choice, I cannot hardcode a specific Case Type.
___________________________________________________________________
I have a Business Rule where I am changing the Case Type based on 3 conditions in the Assignment Group.
BR Condition: Assignment Group changes

3 criteria:
1. Assignment Group has Field 1 (checkbox) = true
2. Assignment Group has Field 2 (List type field) containing Task
3. Assignment Group has Field 3 (Choice field) = Test

Scenario 1
When the Assignment Group satisfies all 3 criteria:
•  If Case Type ≠ Apple → change it to Apple.
•  If Case Type = Apple → leave it unchanged.


Scenario 2
When the Assignment Group does not satisfy all 3 criteria:
•  If Case Type = Apple → restore the Case Type that existed before it was changed to Apple.
•  If Case Type ≠ Apple → leave it unchanged.
•  The original Case Type can be any choice, not necessarily one specific value.

 

Code: 
(function executeRule(current, previous) {

var cond1 = current.field1 == true;

var field2 = current.assignment_group.field2.getDisplayValue();
var cond2 = field2.indexOf('Task') > -1;

var cond3 = current.assignment_group.field3 == 'Test';

// Scenario 1: All three conditions are satisfied
if (cond1 && cond2 && cond3) {

if (current.u_case_type != 'apple') {
current.u_case_type = 'apple';
}

// Scenario 2: Conditions are not satisfied
} else {

if (current.u_case_type == 'apple' && previous.u_case_type != 'apple') {
current.u_case_type = previous.u_case_type;
}
}

})(current, previous);

2 REPLIES 2

s_p_naidu
Tera Expert

Hi @raksh ,
Store the original value(previous original value) in a custom field.
To revert to the original Case Type dynamically without hardcoding you need a custom field on the table(eg:u_original_case_type) to store the value when it changes to 'apple'
Step-1:Create a custom field(eg:u_original_case_type)
Step-2: Update your Business rule script:
(function executeRule(current, previous) {

var cond1 = current.field1 == true;

var field2 = current.assignment_group.field2.getDisplayValue();
var cond2 = field2.indexOf('Task') > -1;

var cond3 = current.assignment_group.field3 == 'Test';

// Scenario 1: All three conditions are satisfied
if (cond1 && cond2 && cond3) {

if (current.u_case_type != 'apple') {

 

 

//when it is not apple store the original case type(previous value) in the variable you created as shown below

current.u_original_case_type=current.u_case_type;
current.u_case_type = 'apple';
}

// Scenario 2: Conditions are not satisfied
} else {

if (current.u_case_type == 'apple' && current.u_original_case_type!='') {
current.u_case_type = current.u_original_case_type;//set the previous value you stored.
current.u_original_case_type='';//clear stored value after restoring
}
}

})(current, previous);


DrewW
Mega Sage

I'm not seeing anything obvious right off the bat, so what have you done to troubleshoot this?

 

Have you looked at the system log to see if your code is erroring?

 

In a subprod have you tested your code in a background script and dumped out the values along the way to make sure they are what you think they are?  You can also use gs.addInfoMessage to the code to see the values that way if you do not want to use a background script to test the code.

 

Is your BR triggering before update and active along with the condition being met?