Make variable fields mandatory after Assign to is filled in. - SCTask

cstac
Tera Contributor

Hello,

I added to mandatory variables that only the tech should fill in once they receive an SCTASK however, for them to receive the SCTASK someone needs to fill in the assign to.  Right now, I cannot fill in the assign to field without the two mandatory variables being filled in at the same time.  Any ideas how to make those variables mandatory after the assign to is not empty?  Thank you!

1 ACCEPTED SOLUTION

The problem is...making them mandatory on_change of the assign_to...still keeps you on the page and unable to "save" or "close" the page because now those fields are mandatory....which is what you said you didn't want to have happen. So say I wanted to assign it to someone...if I "change"...the assigned to to: Bob...immediately on doing that those fields are mandatory....so you're stuck.

 

Please use below code instead.

function onSubmit() {
var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;
if (form.assigned_to != '' && form.getValue('short_description') == "short description from task" && form.getValue('state') == 3) {
form.setMandatory('variables.field_1', true);
form.setMandatory('variables.field_2', true);
 }
if ('variables.field_1' == '' || 'variables.field_2' == '') {
alert("Please fill out field_1 and field_2 before closing task.");
return false;
}
}

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Hi,

So the problem with this is even if it's mandatory after it's assigned...if the user is still on the page after assigning it...they won't be able to save or do anything else because those fields are in fact mandatory.

So you'll want to make an onSubmit client script (using the sc_task table for this...and use script with something like:

function onSubmit() {
var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;
if (form.assigned_to != '' && form.getValue('short_description') == "short description from task" && form.getValue('state') == 3) {
form.setMandatory('variables.field_1', true);
form.setMandatory('variables.field_2', true);
 }
}

And you can add more fields using the example I gave above.

Replace "short description" with description from task.

Replace = 3 for state value of closed or complete, etc.

So you'd have to set those fields as mandatory as they try to submit. If they aren't filled in, it'll inform them of that.

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank you for your response, this works quite well!  I have also ran into the issue where once assign_to is filled out,that the person could go ahead and Close task without filling in the mandatory fields because they did not yet save.  Is there a way to make fields mandatory onchange of the assign_to field?  I have tried altering this script for onchange but it is ignored.  Thank you again.

The problem is...making them mandatory on_change of the assign_to...still keeps you on the page and unable to "save" or "close" the page because now those fields are mandatory....which is what you said you didn't want to have happen. So say I wanted to assign it to someone...if I "change"...the assigned to to: Bob...immediately on doing that those fields are mandatory....so you're stuck.

 

Please use below code instead.

function onSubmit() {
var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;
if (form.assigned_to != '' && form.getValue('short_description') == "short description from task" && form.getValue('state') == 3) {
form.setMandatory('variables.field_1', true);
form.setMandatory('variables.field_2', true);
 }
if ('variables.field_1' == '' || 'variables.field_2' == '') {
alert("Please fill out field_1 and field_2 before closing task.");
return false;
}
}

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

You are so right, I have talked myself into a circle as the problem is I need to be able to assign the ticket to someone and then those fields are required.  But if the user hits close task on the page because those fields become mandatory then Close Task just marks it complete and those fields are blank.  I'm a bit stumped on how to get this done, but your scripts are spot on for each part.  I'm going to have to work with the stakeholder and see where we can meet in the middle here.  Thank you so much!