Script to make a field mandatory after clicking Close Complete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2022 10:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2022 12:42 PM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2022 12:59 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2022 08:12 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 06:22 AM
When I try to put it inside the {} it tells me the code is unreachable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 06:27 AM
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/
Aman Kumar