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

Is this contact_type a dropdown field? If yes, can you please check the "value" for the options phone and self-service pls. You can replace the correct values in the above script and try it out, it should work.


Hi,



The script does work, but what I mean is the script continues to work every time a record is opened. The idea is the contact type is added when the incident is created and not when it is edited. Currently if i open a record opened on the self service portal the first thing it does is change the contact type to phone. Changing the script from onLoad to onSubmit would not fix this issue either as the same issue would occur.


ok gotit, you might want to create a Before Insert business rule and add the following code to it, this will only work when the record is getting inserted and not when it is updated.



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


      current.contact_type = 'phone';


}


else {


      current.contact_type = 'self-service';


}


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


  }


  }


}


Thank you both very much for your help. This works perfectly