How do I pull only the most recent Status Date on a Project # with multiple Status updates?

jl11
Tera Contributor

I am running a report on the Status Report Table and combining fields from the project table as well. 

I have listed the project # and Project Status # with other fields.  The report is pulling all Project Status updates for each Project.  I would like to only pull the most recent Project Status by the most recent Status Date on the Status Report Table.  

Is there a script I can write to state to  Status Date = Most Recent?

 

 

6 REPLIES 6

priya0895
Giga Contributor

Hi all, 

  Thanks for your response but the solutions provided do not work when there are two updates on the same day as the system picks up the most recent randomly of all but not the one updated recently.

  But The below script works as needed. 

After BR on update and insert into status report sets the most recent field to active and false for all the rest of the status reports.

var ps = new GlideRecord('project_status');
ps.addQuery('sys_id', '!=',current.sys_id);
ps.addQuery('project', current.project);
ps.query();
if(ps.next()){
ps.setValue('u_most_recent','false');
ps.updateMultiple();
}
current.update();

Regards
Priya 

Adam Stout
ServiceNow Employee
ServiceNow Employee

I think you want something more like Padmanabam's script above.  Although, I prefer a "Latest Status Report" field on pm_project which holds a reference to project_status so I can dot hop to any field on the status report.   You need to sort the status reports by date (as_on) and get only the latest one.  This will handle filling a late report or anything out of order.  I would fire the BR on any update of project_status.