Make variable field required on SC_TASK closed complete

dagarson
Tera Guru

Hello Im looking for a way to have a vairable field be Mandatory if the Task is set to closed complete.

Basically not allow users to close the SCTASK without filling out the variable. something like this.

find_real_file.png

Any help is appreciated. Thank you.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

I have this requirement often.  An onSubmit Catalog Client Script that Applies on Catalog Tasks is the way to go.  You only need one script per catalog item.  You can, and probably will have many iterations of this requirement - this variable is mandatory on this task and that one, and this one is mandatory if the task is closed complete, incomplete, or skipped,... - all just modifications to the if statements below

function onSubmit() {
  if(g_form.getValue('state') == 3){//Closed Complete
    if(g_form.getValue('short_description') == 'Request a Knowledge Article'){//to make this variable mandatory when only this task closes
      g_form.setMandatory('v_testing_field', true);
      if(g_form.getValue('v_testing_field') == ''){
        alert('Testing field is required');
        return false;
      }
  }
}

View solution in original post

11 REPLIES 11

this worked thank you

You are welcome!

The SN Nerd
Giga Sage
Giga Sage

I was just thinking about this today and was considering which is the best option.

Thought I would come to the community forums to see what people's opinions were.

The different technical solutions I thought about were:

  • onSubmit Catalog Client Script
  • Client Script on Catalog Task
  • UI Policy on Catalog Task (with Script)

I landed on the last option and strongly believe it is the best option.

I think I might write a blog post about it, going into detail as to why. Watch this space.

 


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

@Paul Morris, I have been successfully using the solution I submitted in this thread for at least 5 years. Let me know if you have any questions or more information on what is needed to implement successfully.

I have started drafting my blog for my solution that is low code and maintainable. 

Will post the link when I have published it :).


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022