List type filed update in scope applications

Community Alums
Not applicable

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.

 

Example script1: is not working in scoped app
 
var deptarry = ["89ebf10fdb09c010717624684b96198a", "f324b6271b18bd5063f3ba2d1e4bcbf6", "a0143ee31b18bd5063f3ba2d1e4bcbff"];
var gr = new GlideRecord("x_ryu_finance_finance");
gr.get("0fd2f9e8fbc51290175af4037befdcb0");
gr.department = deptarry.join();
 gr.update();
 
I tried a BR too on x_ryu_finance_finance table with below but no luck
current.department = current.requested_for.u_abc_department;
 
 
Thanks
Ganesh
 
3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

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.

Community Alums
Not applicable

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

 

var deptarry = ["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(gr.number); 
    gr.department = deptarry.join();
    gr.update();
}

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');
}