How do I update a date field using a business rule?

Ryan157
Kilo Contributor

This is related to another post where I was asking how to create a report that will only show the last status report. The advise that I got from one expert user is to create a last_status_report field in the PM table then create a business rule that when "something" change then update the date to the status date. 

I'm hoping someone can guide me thru this process. I can't seem to figure out where my Business Rule is going wrong. 

 

1. Filter Conditions: When Status Date changes 

find_real_file.png

 

2. The field (in the project table) should get updated with the same date as the Status Date (as_on) field. 

find_real_file.png

 

Is there an easier way to do this to make it work? 

 

The last status date field is in the Project Table. I'm hoping when a new Status Report gets created the Business Rules fires off and updates the Last Status date field to be the same as the Status Date. 

1 ACCEPTED SOLUTION

ccajohnson
Kilo Sage

From what I can see your business rule is set to run on insert. If you are expecting the date to change, then you need to make sure that it also runs on Update.

Based upon your second screen shot, your action appears to be updating a field on the Project record and not the Status Report record. This may be why you cannot select the field you just used to trigger the business rule. Unfortunately, you may have to do a bit of coding to achieve this. Typically when we are updating a related record, we set the business rule to Trigger after Insert and Update. I do not currently have PPM installed, but my guess is that the project field name is project and your last status is called u_last_status. If you know what the names are, you can let us know so we can get the Project record through a script and update the Last status field on the Project from the Status date field on the current Status Report record. 

View solution in original post

7 REPLIES 7

SanjivMeher
Kilo Patron
Kilo Patron

In when to run, check the 'Update' checkbox instead of 'Insert' and in the Actions tab, use Set Value Project.Last Status Same As Status Date.

 

If that doesnt work, you may need to write a script by clicking Advanced checkbox and doing a GlideRecord record on Project table and update the Last Status


Please mark this response as correct or helpful if it assisted you with your question.

@sanjiv unfortunately that doesn’t work too. How do I write a glide record?

Ryan157
Kilo Contributor

Hi @Sanjiv - this is what I created and it doesn't seem like to work 😞 

 

(function executeRule(current, previous /*null when async*/) {

u_last_status = GlideDate();

})(current, previous);

 

 

Try if below works.

var p = new GlideRecord('pm_project');

p.get(current.getValue('project'));

 

p.u_last_status = current.as_on;

p.update();


Please mark this response as correct or helpful if it assisted you with your question.