How to set the value for reference field in script.

suuriya
Tera Contributor

Hi ,

 

I have a requirement, based on the filter condition the flash records need to be created in the table.

for example: based on the condition "account number is 006...." then flash record will be created to users who are belong to that account in u_m2m_flashes_users table.

suuriya_0-1696452035107.png

I have written the code it is working fine...now i wanted to create same records in u_flashes table as well....but i not sure how to set the u_account field value

 

This is asyn insert BR.

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

var query = current.getValue('u_condition');
var table = current.getValue('u_table_name');
var usrFlshGr;
var usrGr;
var type = current.getValue('u_type');
var flashess = current.getValue('u_flash'); //
var validto = current.getValue('u_valid_to');
var validfrom = current.getValue('u_valid_from');
if(table == 'u_account'){
gs.info('Flash type is: Account');
var acGr = new GlideRecord('u_account');
acGr.addEncodedQuery(query);
acGr.query();
while(acGr._next()){
gs.info('Flash type Account Number: ' + acGr.u_number);
var ACC = acGr.u_number;
var acUsrGr = new GlideRecord('u_m2m_accounts_users');
acUsrGr.query('u_account', acGr.sys_id); //

acUsrGr.query();
while(acUsrGr._next()){
gs.info('Flash type Account User: ' + acUsrGr.u_user);

usrFlshGr = new GlideRecord('u_m2m_flashes_users');
usrFlshGr.initialize();
usrFlshGr.u_user = acUsrGr.u_user;
usrFlshGr.u_flashes = current.sys_id;
//usrFlshGr.u_type = type;
//usrFlshGr.u_valid_to = validto;
//usrFlshGr.u_valid_from = validfrom;

var sysidfl = usrFlshGr.insert();
if(sysidfl){
gs.info('Flash type Account User Inserted: ' + sysidfl);
var fl = new GlideRecord('u_flashes');
fl.initialize();
fl.u_valid_to = validto;
fl.u_valid_from = validfrom;
fl.u_flash = flashess;
fl.u_type = type;
fl.u_account = ACC;
fl.insert();
gs.info('ACC');
}
}

 

so in this line gs.info('Flash type Account Number: ' + acGr.u_number); the acGr.u_number displays the account number i wanted that account number to be stored in the u_account field in u_flashes table in this l.u_account = ACC;

 

How can i achieve this.

 

As of now everything is set expect account field....last record is actual record created in u_flashes table and top 3 are generated because there is 3 users belong to the mentioned account number

suuriya_1-1696452569770.png

 

Point is I need to store the same account number when the number mentioned in the condition of initial flash record.

Thanks in advance

1 ACCEPTED SOLUTION

Voona Rohila
Kilo Patron
Kilo Patron

Hi @suuriya 

Modify the mapping of account to like this

fl.u_account = acGr.sys_id;
 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

1 REPLY 1

Voona Rohila
Kilo Patron
Kilo Patron

Hi @suuriya 

Modify the mapping of account to like this

fl.u_account = acGr.sys_id;
 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP