- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2020 03:34 PM
Im trying to set the field Contact Type to mobile if the view being used is Mobile so I can use this field for reporting how incidents are getting entered. It the user uses the Now Classic Mobile app I want to know it.
I have the following code in an onLoad Client Script on the Incident form but it is not working - suggestions?
function onLoad() {
//Type appropriate comment here, and begin script below
var viewName = getView();
if(viewName = "mobile"){
contact_type = 'mobile';
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 01:39 PM
Here you go. This script will now check if contact_type already has a value then do not set contact_type as mobile.
function onLoad() {
//Type appropriate comment here, and begin script below
var viewName = getView();
var contactValue = g_form.getValue("contact_type");
if(viewName == "Mobile" && contactValue == ''){
alert("Mobile View");
g_form.setValue('contact_type', 'mobile'); // make sure mobile is the correct value.
}
}
Please mark this CORRECT & HELPFUL if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 06:16 AM
Thanks for your help. It works on Mobile view from the desktop but I am trying to get it to fill in Contact Type = Mobile from NOW Classic Mobile app. I changed the UI Type to All and then tried changing it to Mobile\Portal. No success from the mobile app. Thoughts?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 10:04 AM
use below code
make sure that you are using choice list value of contact_type field and NOT label
function onLoad() {
//Type appropriate comment here, and begin script below
var viewName = getView();
if(viewName = "mobile"){
//contact_type = 'mobile';
g_form.setValue('contact_type','mobile');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 10:05 AM
Hi,
ensure the view name is correct and contact_type field name is correct and the value of contact type i.e. mobile is correct
below should work
function onLoad() {
//Type appropriate comment here, and begin script below
var viewName = getView();
if(viewName == "mobile"){
g_form.setValue('contact_type', 'mobile');
}
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader