Business Rule to Update Reference with Dot-walked value of another reference field

sarahyelton
Tera Expert

I have tried both before and after business rules.  Even if I have "insert" checked, they only ever work on update.  I have two reference fields on the same form.  I want to populate u_tac_business_app with the value of u_business_application (dot walked from the other reference field:  u_tac_record).  This is the current after BR I have.  Please help.

 

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

current.u_tac_business_app = current.u_tac_record.u_business_application;

current.update();

})(current, previous);

1 ACCEPTED SOLUTION

Hello

Agreed with What dirk Said, Never  ever use current.update() in before business rule.

Check field name correctly:

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

gs.log("Check Value :"+current.u_tac_record.u_business_application); /

current.u_tac_business_app = current.u_tac_record.u_business_application;

gs.log("Updated value"+current.u_tac_business_app);

})(current, previous);

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

15 REPLIES 15

 

If the dot walking does not work on the INSERT, I suggest to try with querying the referenced table manually using a GlideRecord on that table to query the data.

Can you check, if that works?

Let me know.

BR

Dirk

 

I am novice at best, could you give me an example script to off of?  Please.  🐵

Hi

Now I just gave it a try to replay your scenario.

I created two separate tables:

find_real_file.png

And the second table:

find_real_file.png

 

Then, I created a Business Rule (on Table A), to complete, what you are asking for:

find_real_file.png

This Business Rule fires on INSERT and UPDATE:

find_real_file.png

 

I tested it on INSERT and UPDATE, and it worked.

Maybe you try to replay my example to review, if that works for you as well, and then transfer that into your specific scenario.

Let me know, if that works, and mark my answer as correct and helpfulm,please.

BR

Dirk

Hi Dirk!

Sorry for the delay; took a mini vacation over the weekend.  The scenario you presented is almost like mine.

Table A (u_technology_access_requests) => Field A (u_business_application; the value I need to copy over)

Table B (u_access_tasks) => Field B (u_tac_record; references record in Table A; the parent) & Field C (u_tac_business_app; a reference field that I need to populate with Table A, Field A)

Both Field A and Field C point to the same reference table (cmdb_ci_business_app).

This is the code I tried using based on your feedback.  Now it isn't working for insert or update.

 

Runs on table:  u_access_tasks, Before, order 100, runs on insert and update

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

current.sysID = current.u_tac_record.u_business_application;

current.setValue = (u_tac_business_app, sysID);

})(current, previous);

HI

Of coure, you need to first create a few records in table B, and then try to capture the records in Table A, by just filling in the reference to one record in table B.

That way, the user captured in table B will be copied over to the new record in Table A.

Let me know, if thats fine for you.

 

BR

Dirk