Displaying additional Variables based on a Hidden variable's value on a Record Producer

JeremyHoffman
Tera Guru

Hello,

We have a record producer that has 19 variables and 7 Catalog UI Policies. There are 2 questions that we ask on the form that drive whether certain fields become visible or remain hidden.

The first field "Is this a new Application or Module?" (new_application_or_module) is Yes/No with None, and always visible.

The second field is "Does this meet the requirements of a project?" (meet_requirements_of_a_project) is Yes/No with None, and is hidden by default and requires a read and write role of it_project_manager (defined in the variable's Permission tab). It is visible and required if new_application_or_module is No and the user has the it_project_manager role.

 

We have 6 additional fields that are hidden by default and need to be displayed when the "Is this a new Application or Module?" is No, and "Does this meet the requirements of a project?" is None or No.

These six fields are 

  • additional_information
  • u_impacted_departments
  • iniative_driving_work
  • business_case
  • u_business_relationship_manager
  • target_completion_date

These variables do not have any conflicting UI Policies associated with them.

I have tried to write a script in the Catalog UI Policy that did not work. I have also tried to use the following conditions:

JeremyHoffman_0-1746716373982.png

For the above condition, I have tried using "is not", "is" and set the value accordingly. I have also deselected the "Reverse if false" 

JeremyHoffman_1-1746716421018.png

and

JeremyHoffman_2-1746716617022.png

 

I can get it to work for the user who has the it_project_manager role and can see the "Does this meet the requirements of a project?" question because it becomes visible. However, it does not work for the typical user who does not see that question (it remains hidden). I have also tried setting the Default value to the "Does this meet the requirements of a project?" question to No which hasn't helped.

 

Early on I tried using a catalog client script but was not successful with that either, sorry I no longer have the code to share. I am not a coder by nature, so that very well could be the solution and I was just coding it wrong.

 

I am hoping someone can help me get this configured properly so the fields show or remain hidden based on the requirements. Please let me know if I need to provide any additional information.

 

Kind regards,

Jeremy

1 ACCEPTED SOLUTION

folusho
Tera Guru

@JeremyHoffman 

 

You want to display the 6 additional fields when:

  • new_application_or_module is "No"

  • AND (meet_requirements_of_a_project is "None" or "No") or the user doesn't have access to that question (field is hidden)

 

I would do the following...

create a Catalog Client Script on the field new_application_or_module. This script will....

  1. Check its value.

  2. Try to get the value of meet_requirements_of_a_project (if visible).

  3. Determine if the 6 other fields should be shown or hidden.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    // List of fields to toggle
    var fieldsToToggle = [
        'additional_information',
        'u_impacted_departments',
        'iniative_driving_work',
        'business_case',
        'u_business_relationship_manager',
        'target_completion_date'
    ];

    // If answer is "yes", always hide the 6 fields
    if (newValue == 'yes') {
        for (var i = 0; i < fieldsToToggle.length; i++) {
            g_form.setDisplay(fieldsToToggle[i], false);
        }
        return;
    }

    // new_application_or_module is "no", now check the second field
    var meetReqVisible = g_form.isVisible('meet_requirements_of_a_project');
    var meetReqValue = g_form.getValue('meet_requirements_of_a_project');

    // Only show the 6 fields if the second question is not visible OR set to "no" or "none"
    if (!meetReqVisible || meetReqValue == '' || meetReqValue == 'no') {
        for (var j = 0; j < fieldsToToggle.length; j++) {
            g_form.setDisplay(fieldsToToggle[j], true);
        }
    } else {
        for (var k = 0; k < fieldsToToggle.length; k++) {
            g_form.setDisplay(fieldsToToggle[k], false);
        }
    }
}

 

View solution in original post

4 REPLIES 4

SumanthDosapati
Mega Sage
Mega Sage

@JeremyHoffman 

I guess the issue is because the hidden field as you cannot getValue of a hidden field to use in condition.

You can try below approach in client script in three consecutive lines:

1. Make the field visible

2. Get the value and store in some var.

3. Make the field hidden again.

Now you can use the var value to define the if condition and show/hide the fields.

 

Hope that helps! Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth

folusho
Tera Guru

@JeremyHoffman 

 

You want to display the 6 additional fields when:

  • new_application_or_module is "No"

  • AND (meet_requirements_of_a_project is "None" or "No") or the user doesn't have access to that question (field is hidden)

 

I would do the following...

create a Catalog Client Script on the field new_application_or_module. This script will....

  1. Check its value.

  2. Try to get the value of meet_requirements_of_a_project (if visible).

  3. Determine if the 6 other fields should be shown or hidden.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    // List of fields to toggle
    var fieldsToToggle = [
        'additional_information',
        'u_impacted_departments',
        'iniative_driving_work',
        'business_case',
        'u_business_relationship_manager',
        'target_completion_date'
    ];

    // If answer is "yes", always hide the 6 fields
    if (newValue == 'yes') {
        for (var i = 0; i < fieldsToToggle.length; i++) {
            g_form.setDisplay(fieldsToToggle[i], false);
        }
        return;
    }

    // new_application_or_module is "no", now check the second field
    var meetReqVisible = g_form.isVisible('meet_requirements_of_a_project');
    var meetReqValue = g_form.getValue('meet_requirements_of_a_project');

    // Only show the 6 fields if the second question is not visible OR set to "no" or "none"
    if (!meetReqVisible || meetReqValue == '' || meetReqValue == 'no') {
        for (var j = 0; j < fieldsToToggle.length; j++) {
            g_form.setDisplay(fieldsToToggle[j], true);
        }
    } else {
        for (var k = 0; k < fieldsToToggle.length; k++) {
            g_form.setDisplay(fieldsToToggle[k], false);
        }
    }
}

 

JeremyHoffman
Tera Guru

@folusho Thank you. Your Client script got me going in the right direction and actually helped me uncover a couple of conflicts I had. I ultimately had to create 2 Client scripts. one as you suggested above, with a few tweaks, and one for the meet_requirements_of_a_project. 
Here are the 2 client scripts I now have and are working per our requirements:
This is the onChange for the new_application_or_module variable (order = 10)

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') return;

    var fieldsToToggle = [
        'additional_information',
        'u_impacted_departments',
        'iniative_driving_work',
        'business_case',
        'u_business_relationship_manager',
        'target_completion_date',
        'primary_application_impacted',
        'u_caregiver_impact'
    ];

    if (newValue === 'Yes') {
        toggleFields(fieldsToToggle, false);
        return;
    }

    var meetReqVisible = g_form.isVisible('meet_requirements_of_a_project');
    var meetReqValue = g_form.getValue('meet_requirements_of_a_project');

    var showFields = !meetReqVisible || meetReqValue === '' || meetReqValue === 'No';
    toggleFields(fieldsToToggle, showFields);
}

function toggleFields(fields, show) {
    for (var i = 0; i < fields.length; i++) {
        g_form.setDisplay(fields[i], show);
    }
}

This is the onChange one for the meet_requirements_of_a_project (order = 20)

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;

    var fieldsToToggle = [
        'additional_information',
        'u_impacted_departments',
        'iniative_driving_work',
        'business_case',
        'u_business_relationship_manager',
        'target_completion_date',
        'primary_application_impacted',
        'u_caregiver_impact'
    ];

    // Show if value is "no" or blank
    var showFields = newValue === '' || newValue === 'No';
    toggleFields(fieldsToToggle, showFields);
}

function toggleFields(fields, show) {
    for (var i = 0; i < fields.length; i++) {
        g_form.setDisplay(fields[i], show);
    }
}

@JeremyHoffman 

Thanks for letting me know and I'm glad this worked for you.

Please can you my response as solution accepted to help others.

 

Regards.