The CreatorCon Call for Content is officially open! Get started here.

How to set the values in the security notes table from user_group table

Ishwar Havagi
Tera Contributor

Hey,

 

I am currently working on a fix script to transfer all the groups from the User Group table to the Security Notes table. To achieve this, I'm fetching values from the User Group table, gliding over to the Security Notes table, initializing objects, and setting values accordingly.

However, I've encountered an issue with fields in the User Group table. The 'Manager' field is a REFERENCE field, and the 'Group Owner' field is a LIST field. When transferring these names to a LIST field, I'm losing the manager's name in the process.

I'd greatly appreciate any insights or suggestions on how to address this issue and ensure that the manager's name is retained in the Group Owner field.

 

Thank you in advance for your help!

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, unfortunately partial screen shots of the 2 fields involved add no diagnostic value, and without details of your code field mapping and the target tables configuration the community can only guess at your issue.


If you are mapping a reference field (Manager) to a string field then you will need to utilize getDisplayValue()
GlideRecord | ServiceNow Developers
or dot walk to the display value field eg myQuery.manager.name

A 'list' field stores the sys_id's of the referenced records, and so for a list you would normally convert the list to an array, then loop through the array using a glideQuery to lookup and retrieve the display field (or any other) from the underpinning records based on sys_id. Something like this

var myArray = myList.split(',');
for(rec in myArray) {
    var myUser = new GlideRecord('sys_user');
    myUser.get(myArray[rec]);
    gs.info(myUser.name);
    gs.info(myUser.getDisplayValue()); 
}

 

Note you could also just user the 'list' as a comma separated string for an encoded query and get same results,

all be it with an extra line of code.

var myUser = new GlideRecord('sys_user');
myUser.addEncodedQuery(myQuery);
myUser.query();
while(myUser.next()) {
     gs.info(myUser.name.toString());
     gs.info(myUser.getDisplayValue()); 
}