Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

roll up dates

Yamja
Tera Guru

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.

1 ACCEPTED SOLUTION

Priyanka0402
Mega Sage

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

View solution in original post

3 REPLIES 3

Priyanka0402
Mega Sage

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

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.

Bert_c1
Kilo Patron

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.