Set current date time in a field using after business rule

Kevin Paul
Mega Guru

Hi All,

 

I have an after business rule that checks if the change request moved to 'Review' state and updates the current date in a field. Can anyone please correct the following script that I've written.

setReviewFields();

function setReviewFields() {
	time = new GlideDateTime();
	current.u_reviewed_at = time;
	current.update();
}

Because of using current.update() I can see that the state transition from 'Implement' to 'Review' is happening twice, so I have decided to use setWorkflow(false) option to stop that. Is there any other way I can write this code? Is there any other way to do it without code?

 

Thanks,

Kevin

1 ACCEPTED SOLUTION

DrewW
Mega Sage
Mega Sage

Doing a current.update in an after BR is never a good idea.

Have you tried putting your code in a Before BR and just setting the order to something over 100k?

Also for your code you should be able to just do

current.setValue("u_reviewed_at", new GlideDateTime());

View solution in original post

4 REPLIES 4

DrewW
Mega Sage
Mega Sage

Doing a current.update in an after BR is never a good idea.

Have you tried putting your code in a Before BR and just setting the order to something over 100k?

Also for your code you should be able to just do

current.setValue("u_reviewed_at", new GlideDateTime());

No I haven't tried, I was fixing this old BR and was thinking if I could do without current.update() in the same after BR. Seems like I have to use update() for this setValue() as well. 

You would need to call current.update if you do not move it to an onBefore rule with a very high order, which really is going to be only 1 of two ways to fix the double update.  The other way to fix the double update is to make the BR run Asynchronous and leave in the current.update.  I think the before update BR would be better.

 

As for the code I was just giving a different way to go about it.

Thank you Drew !