Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

List Collector Issue Passing Value

Cirrus
Kilo Sage

Hi,

Can anyone advise where this script is going wrong please.

On a demand record we have created a list collector field which references cost centre table. A user can select one or many cost centres to associate to the demand.

When the demand is approved, a ui action calls a script include to create a project record associated with that demand. No issues at all with this. As part of the project creation process we want to pass the cost centres selected into a related list on the project record called Affected Cost Centres, and have added the following into the script include:

 

var cost = demand.getValue('u_costing_code');
                   var arr = cost.split(',');
                   for(var i=0; i<arr.length; i++){
                 
                var gr = new GlideRecord('task_cost_center');  
                gr.initialize();
                gr.task = projId; //the id of the new project record created by the script include
                gr.cost_centre = arr[i];
                gr.insert();
                }
 
We can see from logs that if 4 cost centres are selected, the log shows the 4 sys id values. The script creates the 4 new records in the task_cost_center table against the new project number, but the cost centre value is empty.
How can we pass these sys id values into the new records on the task_cost_center table??
1 ACCEPTED SOLUTION

Brad Bowman
Mega Patron

Check the Cost center field name on the task_cost_center table.  It should be

gr.cost_center = arr[i];

 

View solution in original post

4 REPLIES 4

Anand Kumar P
Tera Patron

Hi @Cirrus ,

Update below line of code in your script

var cost = demand.u_costing_code.toString();

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

Hi @Cirrus 

can you Replace the below line

var cost = demand.u_costing_code.toString(); //instead of getvalue

Regards
Harish

Brad Bowman
Mega Patron

Check the Cost center field name on the task_cost_center table.  It should be

gr.cost_center = arr[i];

 

Schoolboy error, well spotted!