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

OlaN
Giga Sage
Giga Sage

Hi,

Something like this perhaps?

 

var userID = current.getValue('u_id');
var userGR = new GlideRecord('sys_user');
if (userGR.get('user_name', userID)) {
  current.setValue('u_user_ref_field_name', userGR.getUniqueValue());
}

 

Akki1
Tera Contributor

Hi @OlaN 

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

How do you upload data in bulk?

Through an import set?

If so, did you uncheck "run business rules" on the transform map?

Akki1
Tera Contributor

Hi @OlaN 

The checkbox is true

I assume the problem is the manager record is not present while that record is being inserted.

But again, if it is after business rule then after all the records are inserted it is running then it should find the records