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

Hi,

you should wrap both the lines within the if condition

var str='';
if(producer.audience_for_assignment!=''){
str=str+''+ producer.additional_details_requirements;
current.description = str;
}

Regards
Ankur

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

Thanks for you assistance but it's still not working.  I'll keep trying to tweak it though.  This is what I've got right now.

var str='';
if(producer.audience_for_assignment!=''){
str = str +''+ producer.audience_for_assignment;
if(producer.producer.additional_details_requirements!='')
str = str +''+ producer.additional_details_requirements;
current.description = str;
}

Hi,

try to add more gs.info() statements and check what's the issue

Regards
Ankur

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

Anirban Roy
Mega Guru

Hi @ToniOxley , 

 

You may loop through the producer object -

for(var varObjItr in producer)

current.work_notes+=producer[varObjItr]+'\n';

 

EDIT:

Editing the comment, since looping the complete producer object might give other properties which are of no relevance.

Hence, please follow below solution -

var test = [];


for(var v in producer){ 


   if (v.startsWith("IO")) { //only variables


       var question = new GlideRecord('item_option_new'); 


       question.get(v.substring(2)); // Querying by sys_id to determine question text


       test += question.question_text + ": " + producer[v] + "\n"; // Set key:value pair to variable


   }


}


current.work_notes = test; // Set Work Notes on new record

 

Reference:

https://community.servicenow.com/community?id=community_question&sys_id=8e8783a9db1cdbc01dcaf3231f96...

 

 

Please mark the answer correct/ helpful, if it helps.

 

Regards,

Anirban

Hello Anirban ,

 

is possible to have question and value in order wise?

like variable v1 have order 100 and  variable v2 have order 200.

 

it should be come like v1 first and then v2  

v1 : 121

v2 : 321

 

Thanks