onChange client script working in default view but not is workspace view

shaik riyaz1
Tera Contributor

Requirement #3 - When "ServiceNow" choice is selected in the "HR system affected" question. Present these options on the "Topic" Question (choices)

- Live Chat Issue
- Virtual Agent/ Virtual Agent Dialogues
- HR Agent Workspace Functionality
- Reporting and Dashboards
- Knowledge Articles
- HR Case Management Model Query
- ServiceNow HRSD Training Content


- Request Forms & Service Portal related issue

I wrote a client script for this which is working fine in default view but it is not working in "workspace view" ...can someone please help on what i'm missing??

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var optionsAll = [
'-- None --',
'Live Chat Issue',
'Virtual Agent/ Virtual Agent Dialogues',
'HR Agent Workspace Functionality',
'Reporting and Dashboards',
'Knowledge Articles',
'HR Case Management Model Query',
'ServiceNow HRSD Training Content',
'Request Forms & Service Portal related issue',
'HR Process design',
'HR AWS',
'HR Groups',
'Request Forms',
'Service Portal menus and other aspects',
'SOPs / Work Instructions',
'Training content',
'Virtual Agent',
'Other'
];
var optionsValuesAll = [
'',
'live_chat_issue',
'virtual_agent_virtual_agent_dialogues',
'hr_agent_workspace_functionality',
'reporting_and_dashboards',
'knowledge_articles',
'hr_case_management_model_query',
'servicenow_hrsd_training_content',
'request_forms_service_portal',
'hr_process_design',
'hr_aws',
'hr_groups',
'request_forms',
'service_portal_menus_and_other_aspects',
'sop_work_instructions',
'training_content',
'virtual_agent',
'other'
];
var hrService = g_form.getValue('u_hr_system_affected');
var topicField = g_form.getControl('u_topic');
topicField.options.length = 0;
if (hrService == 'service_now') {
for (var i = 0; i < 9; i++) {
var option = document.createElement('option');
option.value = optionsValuesAll[i];
option.text = optionsAll[i];
topicField.add(option);
}
} else if (hrService != 'service_now' || hrService == '' || hrService == null) {
for (var j = 0; j < optionsAll.length; j++) {
var optionAll = document.createElement('option');
optionAll.value = optionsValuesAll[j];
optionAll.text = optionsAll[j];
topicField.add(optionAll);
}
}
}


3 REPLIES 3

Ratnakar7
Mega Sage

Hi @shaik riyaz1 ,

 

Here's an updated version of your code that should work in both default and workspace views:

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
    var optionsAll = [
        '-- None --',
        'Live Chat Issue',
        'Virtual Agent/ Virtual Agent Dialogues',
        'HR Agent Workspace Functionality',
        'Reporting and Dashboards',
        'Knowledge Articles',
        'HR Case Management Model Query',
        'ServiceNow HRSD Training Content',
        'Request Forms & Service Portal related issue',
        'HR Process design',
        'HR AWS',
        'HR Groups',
        'Request Forms',
        'Service Portal menus and other aspects',
        'SOPs / Work Instructions',
        'Training content',
        'Virtual Agent',
        'Other'
    ];
    var optionsValuesAll = [
        '',
        'live_chat_issue',
        'virtual_agent_virtual_agent_dialogues',
        'hr_agent_workspace_functionality',
        'reporting_and_dashboards',
        'knowledge_articles',
        'hr_case_management_model_query',
        'servicenow_hrsd_training_content',
        'request_forms_service_portal',
        'hr_process_design',
        'hr_aws',
        'hr_groups',
        'request_forms',
        'service_portal_menus_and_other_aspects',
        'sop_work_instructions',
        'training_content',
        'virtual_agent',
        'other'
    ];

    var hrService = g_form.getValue('u_hr_system_affected');
    var topicField = g_form.getControl('u_topic');
    topicField.options.length = 0;

    if (hrService == 'service_now') {
        for (var i = 0; i < 9; i++) {
            topicField.addOption({
                value: optionsValuesAll[i],
                label: optionsAll[i]
            });
        }
    } else {
        for (var j = 0; j < optionsAll.length; j++) {
            topicField.addOption({
                value: optionsValuesAll[j],
                label: optionsAll[j]
            });
        }
    }
}

 

 

 

If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.

 

Thank you!

Ratnakar

Hi @Ratnakar7 ,

 

Thank you for your response. I am trying to write this in onChange client script. I tried with your updated version. But it is throwing an error stating "Missing function declaration for onChange".


Hi @shaik riyaz1 ,

 

Please try with above edited code.

 

Thanks,

Ratnakar