List type filed update in scope applications

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 10:13 AM
Hello All,
I have department filed which is list type on finance table under finance application. I am trying to update/populate department value with user's department (user is part of multiple departments) from user table (user table has department filed too which is list type, custom one) but the logic is not working in scoped applications (in Global application space it is working as expected) to populate department.
Can someone help me with suggestions/ideas to make this work in scoped apps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 10:23 AM
Where / on what table is this script running? Have you confirmed that the 0fd...cb0 sys_id is a record on the x_ryu_finance_finance table? Your gr.get should be wrapped in an if condition, with the two following lines in an if block. Add some log files to see if/which record is returned.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 10:32 AM
Script is running on "x_ryu_finance_finance" table this script is running,
Yes, "0fd2f9e8fbc51290175af4037befdcb0" is record sys_id
I tried below as well but no luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 10:50 AM
Are you running this as a Fix/Background script or what? Did you see the log containing the number? If you have a field on this table that is a reference to sys_user, you should be able to dot-walk to the custom department list field, but if you want to try with a static list that's fine too. You are joining your array with a space when a list field needs a comma-separated list of sys_ids, which is what you would get from the custom user table field, so either change the .join(',') or change the dept to a string list.
var depts = "89ebf10fdb09c010717624684b96198a,f324b6271b18bd5063f3ba2d1e4bcbf6, a0143ee31b18bd5063f3ba2d1e4bcbff"; // these are sys_id's of departments
var gr = new GlideRecord("x_ryu_finance_finance");
gr.addQuery('number', 'FIN0001245');
gr.query();
if(gr.next()) {
gs.info('SCRIPT: record found ' + gr.number);
gr.department = depts;
gr.update();
} else {
gs.info('SCRIPT: record not found');
}