How to change default value for different views?

Garry Knight
Kilo Contributor

Currently any incidents created by self service users has the "contact type" as "phone" which is our default value for the servicedesk. Is there anyway I can get this to change to our "self-service" option by default. On the self service view "contact type" is not a visible field so is set to phone by default when viewed by us and more importantly we cant track how many incidents are being raised by self service users.. Is there a way I can get it to default to self-service when non-itil users raise an incident using the self service view?

1 ACCEPTED SOLUTION

benn23
ServiceNow Employee
ServiceNow Employee

You probably only want the thing to run when it's loaded for the first time...



function onLoad() {


  if(g_form.isNewRecord()){


  if (g_user.hasRole("itil")) {


  g_form.setValue("contact_type","phone");


  }


  else {


  g_form.setValue("contact_type","self-service");


  }


  }


}


View solution in original post

17 REPLIES 17

pavan_poul
Kilo Expert

Hi Garry,


We have direct option to override the default value of field for tables with dictonary override.


But as for View we dont have direct option, in this case we have to user as fallows



function onLoad() {


  var objView = document.getElementById('sysparm_view');


  var strView = objView.getAttribute('value');


  if (strView == 'ess') {


//set the default value of field


}



Thanks,


Pavan Poul


Jacob_Andersen
ServiceNow Employee
ServiceNow Employee

Garry,



You cannot do this with a client script alone as the field is not on the form.   I'd add the field to the form as a read-only field.   Then, simply control what value it is by setting the field in the module link that is used to open the form.   If you control it this way, then even if you use the CTI integration, you can show the same view but set the field to phone.   This would be preferable over a client script that sets the value based on the view.


You could put the field on the form and then hide it, but still set it via the onLoad script according to the current view.


Garry Knight
Kilo Contributor

Hi Guys,



Thanks for you answers,



Have decided to just set self service as the default value. When this is done the field does not even need to be included on the form, as when ITIL users see it in the default view it defaults to self service. Will just have to get the service desk to remember to change the contact type to phone when we get calls



Thank you both for the help.