set inc short description

varma2
Mega Sage

Hi all,

 

I need to  Auto-populate Short Description with Category- Subcategory on form load  for incident. I have implemented the below code

 

 function onLoad() {
     var category = g_form.getDisplayValue('category');
var subcategory = g_form.getDisplayValue('subcategory');
   
var message = category + '- ' + subcategory;

    g_form.setValue('short_description', message);
}
 
If we use .getDisplayValue  the value setting as Incident Number both  Category and subcategory.
if we use getValue its setting choice value not label.
please suggest.
Thanks all
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@varma2 

so you want choice label so use this

 function onLoad() {
     var category = g_form.getOption('category', g_form.getValue('category')).text;
     var subcategory = g_form.getOption('category', g_form.getValue('subcategory')).text;

     var message = category + '- ' + subcategory;

     g_form.setValue('short_description', message);
 }

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@varma2 

so you want choice label so use this

 function onLoad() {
     var category = g_form.getOption('category', g_form.getValue('category')).text;
     var subcategory = g_form.getOption('category', g_form.getValue('subcategory')).text;

     var message = category + '- ' + subcategory;

     g_form.setValue('short_description', message);
 }

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader