Make Change Request close notes field mandatory with script populated text present?

Happy S
Tera Expert

Hi,

I have a request which is related to the Change Request form, where on form closure, if the close code is unsuccessful then the close notes will auto populate the text - "Explain why this change is not successful?"

 

I am able to populate the text via UI policy script -

------------------
function onCondition() {

g_form.setValue('close_notes', 'Explain why this change is not successful?;
}
------------------

But the issue is the above mentioned text is considered as fulfilling the close notes "mandatory" field condition, and users can just save the form without adding any additional text.

 

So is there a way to make the close notes field mandatory, even with the text - "Explain why this change is not successful?" present and populated?

 

 

HappyJ_1-1694688406532.png

 

 I want the close notes asterix symbol to be in red even with the text populated in the field

HappyJ_0-1694688391106.png

 

 

Thank you

2 ACCEPTED SOLUTIONS

Vishal Birajdar
Giga Sage

Hi @Happy S 

 

Instead of putting text in close notes you can set "Field Message"

 

function onCondition() {
g_form.showFieldMsg('close_notes', 'Explain why this change is not successful?');
}

 

VishalBirajdar7_0-1694689822499.png

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

What is the "When to apply" in UI policy ?

If it is like :

close code is unsuccessful 

VishalBirajdar7_1-1694694423187.png

 

 

 

Then in execute if false script part write :

 

g_form.hideFieldMsg('close_notes',true);

VishalBirajdar7_0-1694694353613.png

 

===========================================================

 

In case you are using onChange client script

 

VishalBirajdar7_0-1694694855822.png

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

7 REPLIES 7

Peter Bodelier
Giga Sage

Hi @Happy S,


First things first. I would not recommend doing this, but instead use annotations for it.

That being said, if you really need to do this, create a onload client script (or in the UI policy you tried already if you want it only on a certain condition):

 

 

 

function onLoad() {
  var notes= g_form.getControl('close_notes');
notes.placeholder = "Explain why this change is not successful?.";
}

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Vishal Birajdar
Giga Sage

Hi @Happy S 

 

Instead of putting text in close notes you can set "Field Message"

 

function onCondition() {
g_form.showFieldMsg('close_notes', 'Explain why this change is not successful?');
}

 

VishalBirajdar7_0-1694689822499.png

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Somehow if I toggle between the Close Codes - successful and unsuccessful the message keeps displaying on top of each other..

 

Anyway to have it display only once?

 

HappyJ_0-1694693694822.png

 

 

 

Hi @Happy S ,

 

Add this in front of the showfieldmsg

 

g_form.hideFieldMsg('close_notes',true);

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.