Need help displaying messages on form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @Everyone
need help on below requirement
Ive requirement when approvals are rejected in authorize state the state transtioned to new state also planned scheduled dates are also changes automatically(which triggered from workflow script)based on this we need to show some message on change request form
thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Teja3
May you consider a business rule. You must check three things:
- Approval is rejected
- The parent record is currently in Authorize state
- Planned dates were moved because of this rejection
Only then you show the message
The Business Rule conditions are
- Table: sysapproval_approver
- When: After
- Update
- Condition:
- state changes to rejected
This table is where approval actions actually happen.
See an example of script
(function executeRule(current, previous) {
var isRejected = current.state == 'rejected' && previous.state != 'rejected';
var parent = current.sysapproval.getRefRecord();
var isAuthorizeState = parent.state == 'authorize';
if (isRejected && isAuthorizeState)
gs.addInfoMessage('Planned dates were moved 7 days forward due to rejection in Authorize state.');
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hey @Teja3
You can achieve this requirement using a combination of Display Business Rule + g_scratchpad + Client Script.
Step 1: Flag the rejection scenario (Server-side)
In your Workflow / Flow Designer / Business Rule where the approval is rejected and the state is reset to New with updated planned dates, set a flag and message:
current.u_rejection_flag = true;
current.u_rejection_reason = "Approval rejected. State reset to New and planned dates recalculated.";
Note: Avoid using current.update() in workflows/flows to prevent recursion and performance issues.
Step 2: Display Business Rule
Table: Change Request
Type: Display
Condition: current.u_rejection_flag == true
Script:
g_scratchpad.showMessage = true;
g_scratchpad.reason = current.u_rejection_reason;
Step 3: Client Script (onLoad)
Type: onLoad
Table: Change Request
function onLoad() {
if (g_scratchpad.showMessage) {
g_form.addInfoMessage(g_scratchpad.reason);
// Optional: highlight impacted fields
g_form.showFieldMsg('start_date', 'Updated due to rejection', 'info');
g_form.showFieldMsg('end_date', 'Updated due to rejection', 'info');
}
}
*****************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hey @Teja3
Hope you are doing well.
Did my previous reply answer your question?
If it was helpful, please mark it as correct ✓ and close the thread . This will help other readers find the solution more easily.
Thankyou & Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb
