How to Set field value based on view

Jon M3
Tera Expert

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';
}
}

1 ACCEPTED SOLUTION

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

Regards,
Muhammad

View solution in original post

12 REPLIES 12

sachin_namjoshi
Kilo Patron
Kilo Patron

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');


}
}

 

MrMuhammad
Giga Sage

try this

function onLoad() {
//Type appropriate comment here, and begin script below
 var viewName = getView();
 if(viewName == "Mobile"){
  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

Regards,
Muhammad

Jon M3
Tera Expert

I tried the code above on an the insert but does not seem to work.  Did it work for you?

The code I provided has worked for me. I tested on my side. You had used single "=" that is assignment operator but we need to use double "==" as we need to compare the values. I replaced accordingly and it worked.

if(viewName == "Mobile")

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad