- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2023 01:47 PM
Hi,
I am trying to roll up my project task actual start date to project actual start date. trying to with business rule on when state changes to work in progress, I want the first actual start date of project task needs to populate as project actual start date.
tried this script.
var ptask = new GlideRecord('pm_project_task');
ptask.addQuery('parent', current.getUniqueValue());
ptask.orderBy('work_start');
ptask.query();
if (ptask.next()) {
current.work_start = ptask.work_start;
}
I don't know why it's not working. orderByDesc(); is working fine but it's takng latest project task actual start date, I want it to be reverse, Please some one help me with code corrections.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2023 10:22 PM - edited 05-07-2023 10:28 PM
Hello @Yamja ,
Please try below code:
var ptask = new GlideRecord('pm_project_task');
ptask.addQuery('parent', current.getUniqueValue());
ptask.orderByDesc('work_start');
ptask.query();
if (ptask.next()) {
current.work_start = ptask.work_start;
current.update();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Priyanka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2023 10:22 PM - edited 05-07-2023 10:28 PM
Hello @Yamja ,
Please try below code:
var ptask = new GlideRecord('pm_project_task');
ptask.addQuery('parent', current.getUniqueValue());
ptask.orderByDesc('work_start');
ptask.query();
if (ptask.next()) {
current.work_start = ptask.work_start;
current.update();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Priyanka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 08:51 AM
Hi Priyanka,
I already tried with orderByDesc();, but the issue is ex: if I create a project task and chenge state to work in progress on 04/15/2023, the project state changes to work in progress and set actual start date to 04/15/2023. but the issue is when I close the project and opening it by creating new project task on 5/8/2023, the actual start date of project changes to 5/8/2023 date instead of 04/15/2023. that is creating an issue.
Please let me know why orderBy(); is not working as orderByDesc(); is working. I want same actual start date needs to be same even after I change WIP to closed complete, then put it back to work in progress.
Please help me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 06:55 AM - edited 05-08-2023 06:57 AM
If the script posted is from a business rule that runs "Before", it should work. Adding "current.update()" is only needed in a Business rule that runs "After". And for that, a line "current.setWorkflow(false);" is needed before "current.update();". More context is needed to determine if the script logic first posted is not working.