Need help displaying messages on form

Teja3
Tera Contributor

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 

7 REPLIES 7

Rafael Batistot
Kilo Patron

Hi @Teja3 

 

May you consider a business rule. You must check three things:

  1. Approval is rejected
  2. The parent record is currently in Authorize state
  3. 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.');

})();

 

 

 

If this response was helpful, please mark it as Helpful and, if applicable, as Correct, this helps other users find accurate and useful information more easily.

vaishali231
Kilo Sage

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












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