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

Here is the screenshot for reference. 

find_real_file.png

Regards,
Muhammad

Here are screenshots from my instance. I am assuming that it should set the Contact Type as soon as the form loads but it is not.

you need to use the code in On Load client script. Currently you have used the code given in business rule. 

Please inactive BR by untick the Active checkbox below Application field.

Create client script and select type as onLoad. 

The script I provided copy that and paste in the script section. See screenshot for reference. 

find_real_file.png

 

Let me know if you face any issue. 

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

Thank you!  I have one other condition - I dont want it to set the value if the contact_type already has a value.  How can I check for that?

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