How to retrieve value from time_worked field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 02:00 PM
Been having difficulty retrieving the value from the time_worked field, with the ultimate goal of summing several time_worked values from child records and then assigning the total to another time_worked field.
If I'm looping through child records via a Business Rule can anyone suggest the correct syntax to achieve this?
Current script is failing and pulling 1970 results:
// Query for child project tasks
var childTasks = new GlideRecord('pm_project_task');
childTasks.addQuery('parent', current.sys_id);
childTasks.query();
// Sum the time_worked field from all child tasks
while (childTasks.next())
{
totalTimeWorked += parseFloat(childTasks.time_worked);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 03:10 PM
Hi @MBarrott ,
If this is your complete script, then the issue is you have not defined the 'totalTimeWorked' variable anywhere.
You have to define it before using it in the while loop, here is an updated script:
// Query for child project tasks
var childTasks = new GlideRecord('pm_project_task');
childTasks.addQuery('parent', current.sys_id);
childTasks.query();
// Sum the time_worked field from all child tasks
var totalTimeWorked = 0;
while (childTasks.next())
{
totalTimeWorked += parseFloat(childTasks.time_worked);
}
Note: Make sure to use correct field names in the script.
Thanks,
Hope it helps.
If my solution turns useful, please mark it helpful and accept solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 08:47 PM
Hi MBarrott,
Thank you! I'll do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2024 09:54 AM
Also after you get that total you would have to add a line in to then fill in the special parent time worked field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2024 01:50 PM
The 'time_worked' field defined on task is type: Timer, a GlideDuration object. that is why you see 1970. You will need to convert to seconds I believe to get anything meaningful.