auto populate date field with latest approval date

BenjaminY
Tera Contributor

My requirement is to auto-populate the 'last_application_date' field with the 'cp_start_date' field from the last request submitted previously with the same 'a_number' field as reference. This field will be read-only on the backend table view only for new records.  Please advise. 

 

 

When to Run:

Before: Insert

last_application is empty

script below:

BenjaminY_0-1736313369218.png

 

5 REPLIES 5

Jon23
Mega Sage

Hi @BenjaminY,

Could you provide details of what is not working with your script?  ie: expected result vs actual result.

 

I would consider removing line3/18, 'if (current.a_number)' and instead use the when to run condition builder for checking 'a_number Is not Empty'

Also, it is not recommended to use 'gr' as a variable name.  alternative example: grCchtTask

 

BenjaminY
Tera Contributor

Thank you, I have updated script with suggestion. Please advise if you may have a solution

@BenjaminY 

Per Ankur Bawiskar comment.

Try using some gs.info statements to ensure the BR is being triggered and you are getting back the info you are expecting.

Example:

  • after line 1 add: gs.info('BenjaminY: BR Triggered');
  • after line 11 add: gs.info('BenjaminY: related record found>> ' + grCchtTask.cp_start_date);
  • after line 12 add: gs.info('BenjaminY: no related record>> ' + current.cp_start_date);

Run a test, check the syslog, filtering on 'Message starts with BenjaminY:'

Depending on what you find in the logs should help you identify the issue.

Ankur Bawiskar
Tera Patron
Tera Patron

@BenjaminY 

please share your updated script and what debugging have you done so far?

Did you verify if GlideRecord gave you the correct record?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader