The CreatorCon Call for Content is officially open! Get started here.

How do I map all variables into the description field & activity log from a record producer

ToniOxley
Kilo Expert

Good Afternoon!

I have created a new record producer for our "Log an incident form" - its quite complex and includes a few different ui policies (for example, if category is protection then show the the protection variable set) - currently i have all the new variables added to the form and the UI policies and actions working perfectly on the front end catalogue form, but on submission, none of the completed fields are been pulled through to the back end incident.

 

Can you please advise how i can get this working?

 

thank you very much ... just an example...

This is our front end form...

As you can see, nothing is mapped across to the back end...

I'm aware its something here that we have to amend...

can you please advise the following;

- what script i need to include all of the completed variables only into the incident record

- how i can amend this going forward if we include more variables sets within the incident record producer

- How i can map all completed variables into the activity log

 

Thank you

18 REPLIES 18

Surbhi Srivasta
Tera Expert

Hi,

We can map the value of variable via two methods:-

1) Using 'Map to fields'

find_real_file.png

 

2) Using Scripting

find_real_file.png

 

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

Regards,

Surbhi

 

Rajaneesh Yarru
Tera Contributor

Hello @Surbhi Srivastava , 

 

What type of script should we use, and whether that's on demand table or record producer table ?

 

Also producer.variable1, here producer is it a keyword for all record producers?

Hi,

You need to use the script in the Record Producer script itself.

Yes, Producer is a keyword here through which ServiceNow identifies Record Producer variables and maps them to the field on the target table.

Refer to the below ServiceNow link for more information:

https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-management/reference/r_CreatingVariablesForFieldTypes.html

Regards, 

Surbhi

Jon Ulrich
Kilo Guru

An updated script for getting all producer variables into the description:

var arr_questionSysIds = [];
for (var v in producer) {
    if (v.startsWith("IO")) { //only variables
        arr_questionSysIds.push(v.substring(2));
    }
}

var gr_questions = new GlideRecord('item_option_new');
gr_questions.addQuery('sys_id', 'IN', arr_questionSysIds.toString()); //Single call to the table with all variables we are looking for
gr_questions.orderBy('order'); //Order by the order they are on the catalog item form
gr_questions.query();
var description = "";
while (gr_questions.next()) {
    var question = gr_questions.getValue('question_text');
    var value = producer[gr_questions.getValue('name')].getDisplayValue();
    if (value !== "") { //only get variables with values
        description += question + ": " + value + "\n"; 
    }
}

current.description = description;

Mi Mi
Tera Contributor

Hi @Jon Ulrich

Thank you so much for sharing your knowledge. It is the script I am looking for. Really appreciate it.

Regards

mm