Script to make a field mandatory after clicking Close Complete

Rylie Markle
Tera Contributor

I wrote a script to make a field mandatory when the fulfiller clicks Close Complete. The script is working for that part, but after the fulfiller completes the field and then clicks Close Complete again, the case doesn't actually close. 

What do I need to add to this script to get the case to actually close after the field is filled in and the fulfiller clicks Close Complete. I know something is missing but I'm not sure what. Thanks in advance. Below is my current script. find_real_file.png

9 REPLIES 9

Try it without the closeCase() function but add the "contents" after the last closing } of the script like this:

current.state = 3;
current.update();
action.setRedirectURL(current);

To give this some better context, here is a UI Action I recently modified to allow the bypassing of all mandatory fields on a Change Request, except one, when clicking the Cancel Change button:

 function setMandatoryFields() {
    for (var i = 0; i < g_form.elements.length; i++){
        var el = g_form.elements[i];
        var fieldName = el.fieldName;
        g_form.setMandatory(fieldName, false); //* override ALL mandatory fields
        g_form.setMandatory('u_cancel_reason', true); //* but keep this one
    }
    gsftSubmit(null, g_form.getFormElement(), 'state_model_move_to_canceled'); //MUST call the 'Action name' set in this UI Action
}

current.state = 4;
current.stage = 'canceled';
current.active = false;
current.update();

Still not working. It just stayed at Work in Progress instead of Closed Complete. 

find_real_file.png

The "gsftSubmit" has to be inside the {} of the function validateFields(). The only part that should be outside of the last } is the "current" items (lines 21, 22, 23)

When I try to put it inside the {} it tells me the code is unreachable. 

Add these line below gsftsubmit function and place gsftSubmit function inside your validatefields function.

if(typeof window == 'undefined')
runBusRuleCode();

function runBusRuleCode(){

//put your server side code

}

Use below link for your reference:

-https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

Best Regards
Aman Kumar