How to make field mandatory on incident form

kumaraj
Kilo Sage

Hi All,

I have a requirement mentioned below, could someone help me to achieve it.

Right now Category field and subcategory fields are not mandatory.

when we make category/subcategory fields mandatory by Client script/UI Policy even then  the user is able to resolve incident bypassing mandatory fields. Now I was told that remove the mandatory tag from both the fields and create a BR which can perform below:

Requirement: If someone tries to update state field then 

if(current.state.changesTo('Resolved/In progress/On hold') && current.category || current.subcategory =='')

then system should abort the action with a message that please category and subcategory filed.

This BR should also prevent updating state when user trying to update by sending email or via service portal. (This is main requirement)  

Thank you

1 ACCEPTED SOLUTION

Upender Kumar
Mega Sage

find_real_file.png

 

	gs.addInfoMessage('Your message');
	current.state=previous.state;
	current.setAbortAction(true);

View solution in original post

15 REPLIES 15

In UI Action try below

function resolveIncident(){
	//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
if(g_form.getValue('category')=='' || g_form.getValue('subcategory')==''){
alert('Fill Category or Subcategory');
return false;
}

	g_form.setValue('incident_state', 6);
	g_form.setValue('state', 6);
	g_form.setValue('resolved_by', g_user.userID);
	
	gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}

Hi Upendra,

 

Thank you for you time and suggestion.

If we make changes in UI action then Incident can be resolved via service portal(We have an Resolve button on SP) and also via email State can be updated, so we are looking for BR.

Below script is also not working as I guess it is aborting the action, so the rest code is not run. Still I have to reload to get state from Resolve to In Progress.

gs.addErrorMessage("your message here");
current.setAbortAction(true);
var url = gs.generateURL(current.getTableName(), current.sys_id);
gs.setRedirect(url);

One more thing, where are we getting the below circled message, i do not see it in "Resolve" UI action

find_real_file.png

Hi Kumaraj

Use On Submit client script

find_real_file.png


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Hi Rohila,

I used that but it does not prevent when someone updating state via email or service portal and therefore we need BR.

We can use data policy but it will impact on other import as well.

 

Try below

gs.addErrorMessage("your message here");
current.setAbortAction(true);
var url = gs.generateURL(current.getTableName(), current.sys_id);
gs.setRedirect(url);