Worknotes automatically updated by system Administrator

Joyal Robert
Tera Contributor

As the per the requirement if the due date field passed the current date it must update the worknotes and in the activity the sytem must show the system administrator.

In order to show the changes for the old records where due date crossed the current date

we had created the onload script  and we set the values and these values are not updated but it is saved. So we created Business rule inorder to update.

 

I will share the screenshot over here

JoyalRobert_0-1716399192543.png

JoyalRobert_2-1716399234522.png

JoyalRobert_3-1716399290405.png

 

Still the result in case form is showing the worknote updated by myself

JoyalRobert_4-1716399379248.png

Please help me on this on priority.

 

Regards,

Joyal Robert

4 REPLIES 4

Arpan Baishya
Kilo Sage

Hi @Joyal Robert,

 

The syntax that you've used for the impersonate method appears incorrect to me. In order to use that method, you need to declare an object of the GlideImpersonate API. See here.  

 

You may try using this method at the beginning of the Business Rule and then, set the Work Notes. Another thing to bear in mind is that you should not be using 'current.update()' in a Business Rule as it is unnecessary and runs counter to best practices.

Hi @Arpan Baishya 

As you can see the screenshot attached, i had set the values in onload client script and i am not able to update from the client script and it is only entering the text in the worknotes, Inorder to update i created a business rule and update it from there. Can you please help me through the given script?

Where i am supposed to add the code in client script or business rule?

Please help me on this.

 

Regards,

Joyal Robert

var impUser = new GlideImpersonate();
impUser.impersonate('enter_sysid_of_the_user_you_want_to_impersonate');

var start_time = new GlideDateTime(current.due_date);
var end_time = new GlideDateTime();
var diff = end_time.getNumericValue() - start_time.getNumericValue();

if (diff > 0) {
current.setValue('state', '10'); 
current.work_notes = 'Update the release date. Current date has crossed the release date.';
}


Replace the code in the Business Rule with the one above and try it out. 

swathisarang98
Giga Sage
Giga Sage

Hi @Joyal Robert ,

 

Instead of impersonating system admin try adding below line in your BR,

 

After updating your worknote add current.autosysfields(false); so it will give updated name as system.

And remove current.update() it is not best practice , potentially lead to a Business Rule calling itself over and over, it will become recursive br.

 

Let me know if it works or not.

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang