Client Script to Update Short Description using multiple variables

Aledis Kedwell
Tera Contributor

Hi Everyone,

I am trying to write an OnChange client script that will update the Short Description on a New Case Record with values derived from the form.

So far I have the following:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    
    var LOB = g_form.getValue('u_lob');
    
    if (LOB == 'DATA' || 'VOICE') {
     
        var myServiceID = g_form.getValue('u_install_base_item');
        var myCategory = g_form.getValue('u_category');
        var myLocation = g_form.getValue('location');
        
        g_form.setValue('short_description', myServiceID + ' | ' + myCategory + ' | ' + myLocation);
    }
    
}

It works...sort of!  at the moment all the values being pulled are the sys_id of the variable, and then obviously these end up in the Short Description field.

How do I set the variables to get the actual displayed value?  I have tried 'getDisplayValue()' but this isn't working as it just brings the Case Number into each variable.

Thanks in advance for your support!

1 ACCEPTED SOLUTION

suvro
Mega Sage
Mega Sage

 

Use below

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    
    var LOB = g_form.getValue('u_lob');
    
    if (LOB == 'DATA' || LOB == 'VOICE') {
     
        var myServiceID = g_form.getDisplayBox('u_install_base_item').value;
        var myCategory = g_form.getDisplayBox('u_category').value;
        var myLocation = g_form.getDisplayBox('location').value;
        
        g_form.setValue('short_description', myServiceID + ' | ' + myCategory + ' | ' + myLocation);
    }
    
}

 

 

 

 

View solution in original post

4 REPLIES 4

suvro
Mega Sage
Mega Sage

 

Use below

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    
    var LOB = g_form.getValue('u_lob');
    
    if (LOB == 'DATA' || LOB == 'VOICE') {
     
        var myServiceID = g_form.getDisplayBox('u_install_base_item').value;
        var myCategory = g_form.getDisplayBox('u_category').value;
        var myLocation = g_form.getDisplayBox('location').value;
        
        g_form.setValue('short_description', myServiceID + ' | ' + myCategory + ' | ' + myLocation);
    }
    
}

 

 

 

 

@Aledis Kedwell 

 

I am glad my response was helpful. If your issue is resolved you can close this thread by marking my response as correct. So that other users having similar query may be benefitted.

 

Thanks and Regards,

Chandra Bose

Thank you suvro...this has worked perfectly!  I was trying to use getDisplayBox() but did not have the '.value' at the end 🙂

Mohith Devatte
Tera Sage
Tera Sage

Hello @Aledis Kedwell ,

These three fields are of which type ? are these referring to any other tables?