How to set a Category and Subcategory mandatory in UI action

AllenGreen
Tera Contributor

In Incident table when I changed the state into resolve the category and sub-category should be mandatory and a popup message should appear like "category and subcategory are not filled" otherwise the state should be In-progress, How can I achieve in UI Action?

 

 

if (current.incident_state == 6); {
    if (g_form.getValue('category') == "" || g_form.getValue('subcategory') == "") {
            g_form.showFieldMsg('category','sub-category','MY ALERT MESSAGE');
        g_form.setMandatory('category','sub-category', true);
            g_form.setValue('state', 6);
        }else
        {
            g_form.setValue('state',2);
        }
}
2 REPLIES 2

Weird
Mega Sage

UI Actions are the buttons on the form or list.
You're probably talking about Client Scripts or a UI Policy.

You can create a onChange Client script or a UI Policy.
For an onChange client script you need to make note of a few things are different from server side scripts. For example you can't use current.

Here's an example script that might help you. Note that I made a few changes.

current.incident_state -> g_form.getValue('incident_state')
sub-category -> subcategory
MSG shown only for field that's missing info. Either way is fine, but imo this makes it clearer to user that only one thing is wrong if the other field is populated.
I've separated the setMandatory and showFieldMsg calls for each field. You can't stack them.

Also, I'm not sure about the else at the end. Are you sure you want to change state to in progress if category and subcategory are filled? You're probably looking for 6 in there as well. I changed this so that if incident_state == 6 then state will always also be 6.

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	if (g_form.getValue("incident_state") == 6){
		if (g_form.getValue('category') == "" || g_form.getValue('subcategory') == "") {
			if(g_form.getValue('category') == ""){
				g_form.showFieldMsg('category', 'MY ALERT MESSAGE');
			}
			if(g_form.getValue('subcategory') == ""){
				g_form.showFieldMsg('subcategory', 'MY ALERT MESSAGE');
			}

			g_form.setMandatory('category', true);
			g_form.setMandatory('subcategory', true);

		}
		g_form.setValue('state', 6);
	}

}

 

Pravindra1
Tera Guru

@AllenGreen you can use same Script in "Resolve" UI action as well.  

 

Just make sure 'Client' checkbox is checked and codes are written under OnClick function. In below example resolveIncident() is the function which will execute after clicking on Resolve button of Incident form. 

Pravindra1_0-1681893596353.png

 

Pravindra1_1-1681893862018.png