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

Sounds like you guys have a working solution, but I wanted to throw out the option of scripting the default value to handle both situations, something like this for the default value field:




javascript:


if (gs.hasRole("itil")) { //modify to specific roles, or has any role etc as needed


      current.contact_type = 'phone';


}


else {


      current.contact_type = 'self-service';


}


Hi Chris,



Have just tried adding this as a client script to the incident table and am receiving:


"


The object "current" should not be used in client scripts.


Error MessageThe object "gs" should not be used in client scripts."


Am I doing something wrong?



Hi Gary,



If you want to put it in a client script, you can use this:-



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


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


}


else {


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


}



Thanks & regards,


Hari


Hi Harikrishnan,



This script works great for when the incident is created, however when someone with the ITIL role opens the incident to have a look it is defaulting it back from self service to phone.



I am thinking making the field a read only could solve the problem?



Thanks for your help


Garry


Update: even as read only the field still changes when the record is opened.