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

Indeed something like this could also work. Be aware that you are setting a reference field. So actually you should pass the sys_id + displayValue. Without displayValue, an additional server lookup is performed (= performance).

Looking at performance, dictionary override would be nicer to use. So have a look if you can manage that.

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

Can you give show me an example of how I would pass the sys_id and display value?

Prasant Kumar 1
Kilo Sage

Hi mkader,

Please refer the below screenshot to fulfill your requirements.

find_real_file.png

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

Thanks & Regards,

Prasant kumar sahu

Thank you for your response @Prasant Kumar Sahu .

The solution you provided is what I already had. My issue is if the user needs to be changed, this script will not allow it, and will therefore default back to the hardcoded user. I needed to set an if condition using the g_form.getValue()

asifnoor
Kilo Patron

Hi,

Check in your client script, if you are setting the assigned_to always. You need to make it only when assigned_to is empty.

Mark the comment as a correct answer and helpful if it helps.