pre-selected value

mouradhadj-
Tera Contributor

Hi,

How to  pre-selecte value on New Location field with the only one available value.
and my field New Location is Reference
i didn't know how to do that ?

8 REPLIES 8

Hi Medi,

I tried your solution but in my code source i am blocked : 

 if (userType == "partner") {
            if (answer["location"].length === 1) {
             
                    g_form.setValue("new_location", answer["location"][0]);
               
            } else {
                g_form.setValue("new_location", ''); // Aucune valeur trouvée, laisser vide
            }
        } else {
            g_form.setValue('new_location', answer["location"]);
        }
    }
i dont' know how to say to select juste one selection when field location has juste one display 

Ankur Bawiskar
Tera Patron
Tera Patron

@mouradhadj- 

I believe you want location to be auto populated when form loads

With what location it should be populated?

With logged in user's location?

If yes then use this in default value of that field

javascript: gs.getUser().getLocation();

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

Hi Ankur,

I tried your solution but in my code source i am blocked : 

 if (userType == "partner") {
            if (answer["location"].length === 1) {
             
                    g_form.setValue("new_location", answer["location"][0]);
               
            } else {
                g_form.setValue("new_location", ''); // Aucune valeur trouvée, laisser vide
            }
        } else {
            g_form.setValue('new_location', answer["location"]);
        }
    }
i dont' know how to say to select juste one selection when field location has juste one display 

@mouradhadj- 

please share complete script and some screenshots of your form and exact requirement

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