Script to pull the record producer variables data into Case Description

Chandana E S
Tera Contributor

Hi,

We have requirement where in there are 30+ variables added to case form using the record producer. These variables are hidden on the service portal and are visible to the user on the native UI after the case is created from the service portal. Once the next user updates the data on the variables displayed on the native case UI, this variables data should be pulled into the Case Description.

I have searched on the community and could find few scripts. I have slightly modified it for my requirement and placed it under the script section of the Record producer. The description pulls all the questions but the responses are always null even when the variables have some answer data. 

With further research, I understood that there should be a business rule to copy those variables data and there should be an onLoad client script for those copied variables to pull into the case description. Can you please guide me with the script as I am still learning with these kind of requirements?

Any help with the script is much appreciated. Thank you!

Here is the script that I had placed under the script section of the Record producer:

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');
if (question!=null) //ignores container end and line breaks
{
var gr_answer = new GlideRecord('question_answer');
gr_answer.addQuery('table_name', current.getTableName);
gr_answer.addQuery('table_sys_id', current.sys_id);
gr_answer.query();
var value = gr_answer.value;
description += question + ": " + value + "\n";     
//var value = producer[gr_questions.getValue('name')].getDisplayValue();
/*  
  if (value !== "") { //only get variables with values
        description += question + ": " + value + "\n"; 
    }
*/
}
}

current.description = description;
8 REPLIES 8

Vamsi Sreenivas
Tera Guru

Hi @Chandana E S ,

 

Can you try updating getTableName to getTableName() in your code.

 

Regards,

Vamsi S

Hi Vamsi,

Thanks for your response. I tried with your suggestion but no luck yet.

Mahendra RC
Mega Sage

Hello @Chandana E S 

Could you please check once with below script in your BR:

var variablesData = [];
var tableGR = new GlideRecord("your_table_name");
tableGR.addQuery("sys_id", current.getUniqueValue());
tableGR.query();
while (tableGR.next()) {
var incVariables = tableGR.variables;
for (var index in incVariables) {
var label = tableGR[index].getLabel();
if (label) {
variablesData.push(label + ": " + tableGR[index].getDisplayValue());
}
}
}
current.description = variablesData.join("\n");

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

Hello @Chandana E S 

Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.

If you still need any further help or guidance on this then please update those on this question.

Thanks