Demand Management

Nitin21
Tera Contributor

Hi, I want to achieve this criteria is demand records. How should I about implementing this.

 

Given the state of a demand record is in "Qualified"

When I select "Defer" or "Return to draft"

Then I should be prompted to provide a reason for this, to provide a future reference. 

AND I should be required to provide this before the record is saved. 

6 REPLIES 6

Rafael Batistot
Tera Sage

Hi @Nitin21 


This two options might help you 

 

 

1. Add a “Reason” field (if not already present)

  • Go to Demand [dmn_demand] table.
  • Create a new field:
    • Name: u_reason_for_state_change (or similar)
    • Type: String (multi-line text)
    • Label: “Reason for State Change”

2.Use an onSubmit Client Script so the user cannot save without a reason:

 

Use a Client Script (onChange or onSubmit):

 

function onSubmit() {
var state = g_form.getValue('state');
var reason = g_form.getValue('u_reason_for_state_change');

// Qualified -> Defer or Return to Draft
if (g_form.getValue('state') == 'defer' || g_form.getValue('state') == 'draft') {
if (!reason) {
g_form.showFieldMsg('u_reason_for_state_change', 'Please provide a reason before saving.', 'error');
return false; // prevents save
}
}
}

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Nitin21 

where are you planning to add Reason once your user provides that

1) If you are planning to use custom field then you can use onChange client script

a) check current State value = Qualifier and New value is Defer or Return to draft

b) if yes then make Reason field mandatory

OR

2) if you are not having any custom field and planning to utilize work notes etc then you can use onChange client script and use prompt() javascript box where user can enter the reason and once you grab the value you can paste in work notes

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

M Iftikhar
Kilo Sage

Hi @Nitin21 ,

You can handle this with a UI Policy or Client Script on the Demand form:

  • Identify when the State field changes to Defer or Return to draft while the current state is Qualified.

  • In that case, make a “Reason” field visible and mandatory.

  • Add a check in a onSubmit Client Script to block saving if the Reason is empty.

This ensures the user is always prompted to enter a reason before the record can be saved.

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.

palanikumar
Mega Sage

You can add a UI Policy to make the Reason mandatory when state is Defer or Return to draft

Thank you,
Palani