Scripting inquiry: If a question is 'yes/no' If yes, make another question auto populate

Andrew Meza
Tera Expert

Hello Community,

 

I have some yes/no questions and also a separate question (dropdown, single line text, or if someone has a recommendation.

 

I need the separate question (sensitivity_level) to automatically be answered based on the yes or no questions. How can I go about this as I am learning more scripting functionality on the platform.

 

If is_this_information_intended_for_public_sharing =yes

make sensitivity_levelPUBLIC

 

If is_this_information_for_internal_use_by_employees_only =yes

make sensitivity_level = INTERNAL USE ONLY

 

If does_the_information_included_sensitive_memeber_data_such_as_personal =yes

make sensitivity_level = CONFIDENTIAL

 

If could_the_authorized_disclosure_of_this_information_result =yes

make sensitivity_level = HIGHLY CONFIDENTIAL

 

If does_this_information_require_encryption =yes

make sensitivity_level = HIGHLY CONFIDENTIAL

 

If is_this_information_regulated_by_laws_or_subject_to_compliance_audits =yes

make sensitivity_level = REGULATORY

 

***This will need to be an OnChange script***

1 ACCEPTED SOLUTION

Pradeep Thipani
Mega Sage

Hi @Andrew Meza ,

 

Here is the example of Catalog onchange script, you can modify the variable's values accordingly.

 

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

    // Fetch values of all yes/no questions
    var publicSharing = g_form.getValue('is_this_information_intended_for_public_sharing');
    var internalUse = g_form.getValue('is_this_information_for_internal_use_by_employees_only');
    var sensitiveMemberData = g_form.getValue('does_the_information_included_sensitive_memeber_data_such_as_personal');
    var authorizedDisclosure = g_form.getValue('could_the_authorized_disclosure_of_this_information_result');
    var requiresEncryption = g_form.getValue('does_this_information_require_encryption');
    var regulatedByLaws = g_form.getValue('is_this_information_regulated_by_laws_or_subject_to_compliance_audits');

    // Determine the sensitivity level based on conditions
    var sensitivityLevel = '';
    
    if (publicSharing == 'yes') {
        sensitivityLevel = 'PUBLIC';
    } else if (internalUse == 'yes') {
        sensitivityLevel = 'INTERNAL USE ONLY';
    } else if (sensitiveMemberData == 'yes') {
        sensitivityLevel = 'CONFIDENTIAL';
    } else if (authorizedDisclosure == 'yes' || requiresEncryption == 'yes') {
        sensitivityLevel = 'HIGHLY CONFIDENTIAL';
    } else if (regulatedByLaws == 'yes') {
        sensitivityLevel = 'REGULATORY';
    }

    // Set the sensitivity level field value
    if (sensitivityLevel !== '') {
        g_form.setValue('sensitivity_level', sensitivityLevel);
    }
}
"If this response was useful, please select 'Accept as Solution' and mark it as 'Helpful.' This helps me provide better answers and assists the community ".

Regards,
Pradeep

View solution in original post

3 REPLIES 3

Pradeep Thipani
Mega Sage

Hi @Andrew Meza ,

 

Here is the example of Catalog onchange script, you can modify the variable's values accordingly.

 

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

    // Fetch values of all yes/no questions
    var publicSharing = g_form.getValue('is_this_information_intended_for_public_sharing');
    var internalUse = g_form.getValue('is_this_information_for_internal_use_by_employees_only');
    var sensitiveMemberData = g_form.getValue('does_the_information_included_sensitive_memeber_data_such_as_personal');
    var authorizedDisclosure = g_form.getValue('could_the_authorized_disclosure_of_this_information_result');
    var requiresEncryption = g_form.getValue('does_this_information_require_encryption');
    var regulatedByLaws = g_form.getValue('is_this_information_regulated_by_laws_or_subject_to_compliance_audits');

    // Determine the sensitivity level based on conditions
    var sensitivityLevel = '';
    
    if (publicSharing == 'yes') {
        sensitivityLevel = 'PUBLIC';
    } else if (internalUse == 'yes') {
        sensitivityLevel = 'INTERNAL USE ONLY';
    } else if (sensitiveMemberData == 'yes') {
        sensitivityLevel = 'CONFIDENTIAL';
    } else if (authorizedDisclosure == 'yes' || requiresEncryption == 'yes') {
        sensitivityLevel = 'HIGHLY CONFIDENTIAL';
    } else if (regulatedByLaws == 'yes') {
        sensitivityLevel = 'REGULATORY';
    }

    // Set the sensitivity level field value
    if (sensitivityLevel !== '') {
        g_form.setValue('sensitivity_level', sensitivityLevel);
    }
}
"If this response was useful, please select 'Accept as Solution' and mark it as 'Helpful.' This helps me provide better answers and assists the community ".

Regards,
Pradeep

Thank you for this. Am I setting this up correct? At the moment it is not working like intended.

AndrewMeza_0-1727712916041.png

AndrewMeza_1-1727712958356.png

 

 

Hi @Andrew Meza ,

 

Make sure all the backend values are mapped correctly to the script.

 

Choose the Variable name as the first yes/no question field (for example, is_this_information_intended_for_public_sharing) below the OnChange.

"If this response was useful, please select 'Accept as Solution' and mark it as 'Helpful.' This helps me provide better answers and assists the community ".

Regards,
Pradeep