auto populate date field with latest approval date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 11:06 AM - edited 01-07-2025 09:16 PM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 06:25 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 09:17 PM
Thank you, I have updated script with suggestion. Please advise if you may have a solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 05:13 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 09:46 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader