Can I override required fields through scripting in SBM Teamtrack?

ProcessMan's picture
ProcessMan asked on September 2, 2011 - 5:40pm | Replies (10).

Hello,

I want to give the user a checkbox to override required fields. For instance, if its an emergency software install I don't want the user to select a scheduled release date.

If that's not possible, is there a way to dynically change the form field label color?

Right now to solve this problem I have a script that generates error message based on the field logic. For instance, if override is not selected the user must fill in a date value. If they don't my script pushes out an error on the form. I have pre-colored the text to red, but, if the user fills out the form the label is still red.

Any suggestions will be helpful.

Thanks,

processman

10 Answers

jptownsend's picture
jptownsend replied on September 6, 2011 - 2:54pm.

Process Man,

You could make the required fields dependent on the check box field, that if they select override as one of the check boxes that the required fields change to the selection of Overidden if they are selection fields, if they are text fields then this wouldn't help but if they are selection this would be the easiest route to consider.

Regards,

Joe

Anonymous's picture
Anonymous replied on September 13, 2011 - 8:16pm.

If you are running SBM, you can add a form to the workflow and use javascript to control the fields.

For example here's a snippet that displays a field called 'RFC' if the priority is 'Critical'. Otherwise the field is optional and hidden.

function priorityChanged() {
var text = GetFieldValue("PRIORITY");
if (text == "1 - Critical") {
ShowField("RFC");
MakeFieldRequired("RFC");
} else {
MakeFieldOptional("RFC");
HideField("RFC");
}
}

ProcessMan's picture
ProcessMan replied on September 13, 2011 - 8:55pm.

Thanks for your help, that's great to know. I'll give it a try.

ProcessMan's picture
ProcessMan replied on December 2, 2011 - 4:05pm.

Created the same fields as in your script, but now I'm not entirely sure where to place the code. I've tried a few things, like adding/importing the javascript to the form.

I'm not a javascript guru.

When I display the form the javascript is not invoked. Am I missing something? How is the function invoked?

Anonymous's picture
Anonymous replied on December 2, 2011 - 4:14pm.

You also need to tell the form when to invoke that function.

In this example you'll want the function to be called when the PRIORITY file is changed. So, add this to the javascript file:

AddChangeCallback('PRIORITY', priorityChanged);

You'll also want to execute the function when the page is loaded, so you'll also add:

AddLoadCallback(priorityChanged);

The SBM Composer Guide has a section on the available javascript functions.

ProcessMan's picture
ProcessMan replied on December 2, 2011 - 6:19pm.

Wow, it works!

I had just found the appanedix but your example did the trick. Thanks for giving me the little push to help me over the top!

ProcessMan's picture
ProcessMan replied on December 6, 2011 - 12:07pm.

What am I doing wrong now? I'm trying to hide and display a field based on a checkbox on a binary/Trinary field. It's hiding the field by default but when I check the field it does not make the field appear.

AddChangeCallback('Emergency Install', priorityChanged);

AddLoadCallback(priorityChanged);

function priorityChanged() {

var textvar = IsFieldChecked("Emergency Install");

if (textvar == "true")
{
ShowField("Emergency Justification");
MakeFieldRequired("Emergency Justification");
} else {

MakeFieldOptional("Emergency Justification");
HideField("Emergency Justification");

}
}

Anonymous's picture
Anonymous replied on December 6, 2011 - 2:49pm.

The IsFieldChecked returns the value true or false, it's not a string. So try this:

if (textvar == true)
{
...
}

Or you can simplify it like this:

if (IsFieldChecked('Emergency Install'))
{
...
}

ProcessMan's picture
ProcessMan replied on December 6, 2011 - 6:20pm.

OK, getting closer.

If I check the check box nothing happens, but if I additionally click in a blank area in the form the field related to the check box shows itself.

The logic is working, the field/form is not refreshing. I'm going to RTFM some more and hopefully find a solution.

ProcessMan's picture
ProcessMan replied on December 6, 2011 - 7:06pm.

Got it! Had to add the AddRadioCallback to make it work.

AddLoadCallback(priorityChanged);

AddChangeCallback('EmergencyInstall', priorityChanged);

AddRadioCallback("EmergencyInstall",priorityChanged),

function priorityChanged() {

if (IsFieldChecked('EmergencyInstall'))
{
ShowField("RFC");
MakeFieldRequired("RFC");
} else {
MakeFieldOptional("RFC");
HideField("RFC");
}
}

CMCrossroads is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.