how to set mandatory on close notes field in requested item

TMKAM
Tera Contributor

I have created an UI Action "Cancel Request" button as per below in the requested item table and I want to add the existing scripts when the assignee clicks on the UI Action "Cancel Request" button it will force or set a mandatory to fill in the close notes comment.

 

How can I do script it and thank you.

 

Condition

current.approval == 'requested'

 

Scripts

current.state = '4';
current.approval = 'Cancelled';
current.update();

2 ACCEPTED SOLUTIONS

pethumdesilva
Tera Guru

Hi TMKAM

 

Create a new client script for RITM
type: onSubmit
 
in the script 
get the action (assume your UI action action name "cancel_request"
 
function onSubmit() {
 
 var action = g_form.getActionName();
   if (action != 'cancel_request')
      return;
  
  
// Close notes and Close code must be on the form   
   if (!g_form.hasField('close_notes'))
      return;
  
  
 g_form.setDisplay('close_notes', true);
   g_form.setMandatory('close_notes', true);
   
if (g_form.getValue('close_notes') == '')
      return false;   
}
 
Regards,
Pethum

View solution in original post

Pavankumar_1
Mega Patron

Hi @TMKAM ,

try below script and give action name as reject_action and select Client check box.

Give onClick function name as reject() or any name must use same function on script.

function reject() {
	g_form.setMandatory('close_notes', 'true');
	var answer = confirm("Are you sure you want to Cancel Request?");
	if (answer == true) {
		gsftSubmit(null, g_form.getFormElement(), 'reject_action'); //MUST call the 'Action name' set in this UI Action
	} else {
		return false;
	}
}
if (typeof window == 'undefined') {
	current.state = '4';
	current.approval = 'Cancelled';
	current.setWorkflow(false);
	current.update();
}

Screenshot (824).png

Screenshot (825).png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

7 REPLIES 7

Samaksh Wani
Giga Sage
Giga Sage

Hi,

 

function onClick(){
g_form.setMandatory('work_notes', true);
}

 

Plz mark my Solution as Accept and Thumbs up, if you got any help from it.

 

Regards,

Samaksh

Hello @TMKAM 

 

This is my Response,

 

Plz mark my Solution as Accept and Thumbs up, if you got any help from it.

 

Regards,

Samaksh

 

Samaksh Wani
Giga Sage
Giga Sage

Hello, 

 

I have also added the same line of code for that.

 

Can you pls mark my solution as Accept, it will help other users to reach out here.

 

Regards,

Samaksh