- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 01:54 AM
Dear All,
We have a business rule to sum up all the Efforts <u_effort_man_day> of a CTASK and display it to the Demand field Estimated Effort <u_effort_man_days>. Here is my code:
var dmnd = new GlideRecord('dmn_demand');
dmnd.addQuery('u_demand',current.sys_id);
dmnd.query();
var ctsk = new GlideRecord('change_task');
ctsk.addQuery('sys_id',current.u_demand);
ctsk.query();
var parCtask = parseFloat(ctsk.u_effort_man_day.replace(/,/g,''));
if(dmnd.next()){
var count = 0;
while(ctsk.next()){
if(ctsk.u_demand_task_type == 'screening'){
count += parseFloat(parCtask); //u_effort_man_days field on change task
}
}
dmnd.u_effort_man_days = count; //u_effort_man_days field on demand
dmnd.update();
}
Apparently, this code is not working. Can you tell me what's wrong? Many thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 02:36 AM
Hi Shishir,
Thank you so much for your response, I appreciate your help. I was able to sum up the effort by using the below code:
var dmnd = new GlideRecord('dmn_demand');
dmnd.addQuery('sys_id',current.u_demand);
dmnd.query();
var ctsk = new GlideRecord('change_task');
ctsk.addQuery('u_demand',current.u_demand);
ctsk.query();
if(dmnd.next()){
var count = 0;
while(ctsk.next()){
if(ctsk.u_demand_task_type != 'screening'){
count += parseFloat(ctsk.u_effort_man_day); //u_effort_man_days field on change task
}
}
dmnd.u_effort_man_days = count; //u_effort_man_days field on demand
dmnd.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 02:33 AM
Hi Diane,
Please find few suggestions below.
var dmnd = new GlideRecord('dmn_demand');
dmnd.addQuery('sys_id',current.sys_id);
dmnd.query();
gs.log(dmnd.getRowCount());
while(dmnd.next()){
var count = 0;
var ctsk = new GlideRecord('change_task');
ctsk.addQuery('sys_id',dmnd.u_demand); //Hoping u_demand is a reference field on dmn_demand table and contains the Change Task number
ctsk.query();
while(ctsk.next()){
var parCtask = ctsk.getValue('u_effort_man_day').replace(/,/g,''); //do we need replace here?
if(ctsk.getValue('u_demand_task_type') == 'screening'){
count = parseFloat(count) + parseFloat(parCtask); //u_effort_man_days field on change task
}
}
dmnd.u_effort_man_days = count; //u_effort_man_days field on demand
dmnd.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 02:36 AM
Hi Shishir,
Thank you so much for your response, I appreciate your help. I was able to sum up the effort by using the below code:
var dmnd = new GlideRecord('dmn_demand');
dmnd.addQuery('sys_id',current.u_demand);
dmnd.query();
var ctsk = new GlideRecord('change_task');
ctsk.addQuery('u_demand',current.u_demand);
ctsk.query();
if(dmnd.next()){
var count = 0;
while(ctsk.next()){
if(ctsk.u_demand_task_type != 'screening'){
count += parseFloat(ctsk.u_effort_man_day); //u_effort_man_days field on change task
}
}
dmnd.u_effort_man_days = count; //u_effort_man_days field on demand
dmnd.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 02:39 AM
cool, that means there was an issue with if condition. Thank you for the update.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 02:41 AM
issue was in line number 2. good job dianemiro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 02:44 AM
Thank you guys for your help. The new lines of code "logs" and "getvalue" will be useful in the future.