How to trigger a business rule when any variable within a multi row variable set changes?

Charlie Hudson
Tera Contributor

I'm trying to trigger a business rule on the sc_req_item table on the condition when any variable within a multi-row variable set changes. current.variables.changes() works fine for variables outside of MRVS but not variables inside.

I've also tried current.variables.*variablesetname*.changes() but that gives an error

Any suggestions? Thanks

1 ACCEPTED SOLUTION

@Charlie Hudson 

you cannot determine if MRVS got changed or not

you will have to take another approach

1) Create a hidden variable on your catalog item of type string

2) Set this with the value from MRVS using run script of workflow

Run script in workflow:

current.variables.<hiddenVariable> = current.variables.product_model;

current.setWorkflow(false);

current.update();

3) then use after update BR

Condition: current.variables.changes()

Script:

1) get the current value of MRVS

2) you already have the original value of MRVS in the hidden variable

3) compare both the json array and then determine if anything changed

Refer below link on how to compare 2 json array of strings

Comparing two json arrays

How to check if JSON array is equal to

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

asifnoor
Kilo Patron

Hi,

In place of varaiblesetname did you gave the actual variable set name?

Also, can you share the error here once.

 

So when I try this condition, "product_model" is a MRVSfind_real_file.png

I get this error:

find_real_file.png

which I don't get when it's just current.variables.changes()

@Charlie Hudson 

you cannot determine if MRVS got changed or not

you will have to take another approach

1) Create a hidden variable on your catalog item of type string

2) Set this with the value from MRVS using run script of workflow

Run script in workflow:

current.variables.<hiddenVariable> = current.variables.product_model;

current.setWorkflow(false);

current.update();

3) then use after update BR

Condition: current.variables.changes()

Script:

1) get the current value of MRVS

2) you already have the original value of MRVS in the hidden variable

3) compare both the json array and then determine if anything changed

Refer below link on how to compare 2 json array of strings

Comparing two json arrays

How to check if JSON array is equal to

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Charlie Hudson 

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

If not, please let us know if you need some more assistance.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader