Client Script Populate Message if fields are empty

Simran321
Tera Expert

I have a client script that needs to add an message if all the four fields on case is empty and State is changed to close complete. 

The script is below

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

{

if (g_form.getValue('u_does_a_help_article_exist_for_this')=='' && g_form.getValue('u_does_a_documented_process_and_or_template_exist_for_this') == ''&& g_form.getValue('u_does_a_new_category_need_to_be_created_for_this_case') == ''&& g_form.getValue('u_was_this_ticket_initially_assigned_to_the_correct_assignment_group') == '' && g_form.getValue('u_hr_agent_case_notes') == ''){
g_form.addInfoMessage('Case Resolution Details fields are empty');
return false;
}
}
}

 

This script is working fine. However, I want this message not to populate if hr service is ac8637a4db431450382960ab139619e2 or 0dd013e8db425010382960ab13961925

I added this info to line 7 now

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == '3')
{
if (hr_service != 'ac8637a4db431450382960ab139619e2'|| hr_service != '0dd013e8db425010382960ab13961925')
{
if (g_form.getValue('u_does_a_help_article_exist_for_this')=='' && g_form.getValue('u_does_a_documented_process_and_or_template_exist_for_this') == ''&& g_form.getValue('u_does_a_new_category_need_to_be_created_for_this_case') == ''&& g_form.getValue('u_was_this_ticket_initially_assigned_to_the_correct_assignment_group') == '' && g_form.getValue('u_hr_agent_case_notes') == ''){
g_form.addInfoMessage('Case Resolution Details fields are empty');
return false;
}
}
}
}

 

The script is not throwing error but when I am trying to mark the state to closed complete I am getting an error below

 

onChange script error: ReferenceError: hr_service is not defined function () { [native code]

 

It seems like I need to define hr_service somewhere

 

Can someone please help?

 

 

 

 

1 ACCEPTED SOLUTION

BharathChintala
Mega Sage

@Simran321 

2 mistakes didn't define hr_service and used || for != always && for !=

 

Try below script

 

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

var hrservice = g_form.getValue('hr_service');
if (hrservice != 'ac8637a4db431450382960ab139619e2' && hrservice != '0dd013e8db425010382960ab13961925'){
if (g_form.getValue('u_does_a_help_article_exist_for_this')=='' && g_form.getValue('u_does_a_documented_process_and_or_template_exist_for_this') == ''&& g_form.getValue('u_does_a_new_category_need_to_be_created_for_this_case') == ''&& g_form.getValue('u_was_this_ticket_initially_assigned_to_the_correct_assignment_group') == '' && g_form.getValue('u_hr_agent_case_notes') == ''){
g_form.addInfoMessage('Case Resolution Details fields are empty');
return false;
}
}
}
}

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

View solution in original post

1 REPLY 1

BharathChintala
Mega Sage

@Simran321 

2 mistakes didn't define hr_service and used || for != always && for !=

 

Try below script

 

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

var hrservice = g_form.getValue('hr_service');
if (hrservice != 'ac8637a4db431450382960ab139619e2' && hrservice != '0dd013e8db425010382960ab13961925'){
if (g_form.getValue('u_does_a_help_article_exist_for_this')=='' && g_form.getValue('u_does_a_documented_process_and_or_template_exist_for_this') == ''&& g_form.getValue('u_does_a_new_category_need_to_be_created_for_this_case') == ''&& g_form.getValue('u_was_this_ticket_initially_assigned_to_the_correct_assignment_group') == '' && g_form.getValue('u_hr_agent_case_notes') == ''){
g_form.addInfoMessage('Case Resolution Details fields are empty');
return false;
}
}
}
}

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala