how to Set field value in reference field using BR

Akki1
Tera Contributor

Hi,

How to set reference field value using Business rule?

I have 2 fields on a custom table

u_id-String

UserRef-reference to sys_user

I want Business rule code that when u_id is filled or updated it should go glide record using u_id field to match UserId in sys_user table and that record should be updated in UserRef

15 REPLIES 15

Hi @Ankur Bawiskar 

I have a custom table u_accounts

fields are:

User_id

first_name

last_name

Manager-String

manger_Identity-Refernce to self table(u_accounts)---not visible on form

Manager_User_Id-String---not visible on form

 

I have written after business rule on insert/update with condition Manager_User_Id changes

var gr=new GlideRecord('u_accounts');

gr.addQuery('user_id',current.Manager_user_id);

gr.query();

if(gr.next()){

current.manger_Identity=gr.getValue('sys_id');

}

current.update();

 

It is working fine if i submit using form but it is not working when i upload data in bulk

 

 

 

Hello,

 

In the transform map please check if the run business rule checkbox is set to true.

 

Saurav11_0-1666075804626.png

 

 

Also make sure there are no transform script in that transform map which has the below syntax:-

 

setWorkflow(false);

 

Also wondering instead of using business rule why not use a advance qualifier as below:-

 

javascript: 'user_id='+current.Manager_user_id; 

 

Please mark answer correct based on Impact.

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

You do not need a business rule you can do it using advance reference qualifier.

 

Open the dictionary of the userRef field and add the below line in the advance qualifier:-

 

javascript: 'user_name='+current.u_id; 

 

Saurav11_1-1665733575071.png

 

Please mark answer correct/helpful based on Impact.

Akki1
Tera Contributor

but it is a refernece qualifier I want that field to be updated with that record.

And this is reference to the same table 

The manager_user_id is one field right and and manger_Identity is one field so if I am understanding it correctly it should work fine. Can you give it a try?

 

javascript: 'user_id='+current.Manager_user_id;