Auto populate Assigned to field on a new incident

mkader
Kilo Guru

Hello,

I am trying to auto populate the assigned to field on an incident form with a particular user. I am able to do this using a client script using onSubmit type:

g_form.setValue('assigned_to', 'Sys ID of User');

The only problem I have here is that if the assigned to field needs to be changed/updated, It will not save. This user will be permanently assigned to the incident. How can I set it up in a way that allows the assigned to field to be defaulted to that particular user, but if the assigned to needs to be updated with someone else, the system will allow it?

EX:

when I use the provided client script, Tom Jones fills the assigned to field, but when I come back in to modify the field with Jessica Alba and then click save, the field repopulates with Tom Jones and not Jessica Alba.

Thanks!

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have you considered using a default value on the assigned_to field instead (maybe dictionary override on assigned_to, because incident is task extended)? Don't see a reason in your question for doing this client side and onsubmit?

If still wanting to do this onSubmit: add an If condition which checks if the assigned_to is different then the sys_id you are trying to set.  

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

I forgot to mention that this is a custom incident table. How can I do this in a way that does not affect the task table? When I configure the dictionary, It shows the field coming from the task table. I was unsure of how to default a value on this particular table that has been created

Sorry I am new to ServiceNow and still trying to figure things out. 

Dictionary override would be your go to.

find_real_file.png

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Just figured it out.

Thanks, was not thinking of setting an If condition if the value was empty.

function onLoad() {
   if((g_form.getValue('assigned_to')=='')){
     g_form.setValue('assigned_to','Sys ID of user'); // Tom Jones
   }
}