How to map a field from a record producer using scripts

Dhanya
Kilo Contributor

Hi i need help with a catalog client script. i'm trying to pass a value from the record producer to the incident based on value selected by the user. I understand we cannot use current to refer to the incident form,

if ((producer.team)== 'MAC'){
g_form.setValue('assignment_group','MAC-Support');}

i need this value to be mapped to the field in incident. But this is not working.

15 REPLIES 15

Hi,

this you need to add in record producer script which is server side

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

ok i added that but it is not working in my case.

the if statement is not working, i had tried adding anther statement also earlier. 

Is there anything that i might be missing?

Hi Dhanya,

what type of variable is team? is it string?

Is MAC-Support correct group name?

Can you share the updated script again?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Kieran Anson
Kilo Patron

Hi,

If this is a catalogue client script, I presume you're using an onChange script? change to the below:

Type: onChange

VariableName: team

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    if (newValue == 'MAC') {
        g_form.setValue('assignment_group', 'sysid_of_assignment_group');
    }
}

Do add the display value as well. Only providing the sys_id on reference type fields/variables in a client script causes an additional database query to be made (= performance loss).

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

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn