Help with Record Producer Script - Having issues pulling Sys ID

Wendy Peterson
Giga Guru

Someone helped me with this for a Table I have which in the Record Producer I have tons of variables but they only want to see the ones are that complete. I can get it to pull the values if i tell it the sys id to look for but I can't get it to pull the sys id of the record it just created. Any ideas? See the screenshot below the sys id is there and it's unique. TIA It's for a Record Producer that is put into a table with only like 4 fields and one of them is a comments section it wants the variable values to go into if they are completed. If they aren't completed they don't want to see them.

var gr = new GlideRecord('question_answer');  

gr.addQuery('table_sys_id', current.sys.id); //sys_id of record in question      

gr.query();  

while (gr.next()) {  

  if (gr.value && gr.question.type == 6) { //exclude questions with empty values  

  current.u_comments +=(gr.question.getDisplayValue() + ":   " + gr.value.getDisplayValue() + "\n"); //display question and answer  

  }  

}    

current.u_aom_analyst = gs.getUserID();  

2017-12-19_15-25-26.png

1 ACCEPTED SOLUTION

Hi Wendy,



Can you please try the following and let me know how you get along: -



var sysID = current.getUniqueValue(); //find sys_id of current record



var gr = new GlideRecord('question_answer');


gr.addQuery('table_sys_id', sysID); //sys_id of record in question


gr.addNotNullQuery('value'); //exclude any variables with null values


gr.query();



var myComments = '';



while (gr.next()) {


  if (gr.question.type == 6) { //restrict question type


        myComments +=(gr.question.getDisplayValue() + ":   " + gr.value.getDisplayValue() + "\n"); //build comments


  }


}


//set fields on record producer


current.u_comments = myComments;


current.u_aom_analyst = gs.getUserID();





I could only test this in a background script with a fixed sys_id so you'll have to let me know if it works for you.


View solution in original post

17 REPLIES 17

So I just did this one and what I want to happen is for it to put the bottom variables in the comments area





In the script section of the record producer, you just need to add code like this:



var notes = "Details:\n";


          notes += "\nSelect your Assignment Group:" + producer.assignment_group.getDisplayValue();


          notes += "\nWeek Of " + producer.week_of.getDisplayValue();


//add so on


          current.comments =   notes;



make sure you update the variable name to match your variable name: producer.variable_name.getDisplayValue()


I only want it to show the ones with Values not the empty ones. I think there are 40 fields on there and probably only 3 would show. The script worked when I was looking for a specific ID and can put them all in the notes fine just by using the names etc but they don't want to see all of them


Hi Wendy,



Can you please try the following and let me know how you get along: -



var sysID = current.getUniqueValue(); //find sys_id of current record



var gr = new GlideRecord('question_answer');


gr.addQuery('table_sys_id', sysID); //sys_id of record in question


gr.addNotNullQuery('value'); //exclude any variables with null values


gr.query();



var myComments = '';



while (gr.next()) {


  if (gr.question.type == 6) { //restrict question type


        myComments +=(gr.question.getDisplayValue() + ":   " + gr.value.getDisplayValue() + "\n"); //build comments


  }


}


//set fields on record producer


current.u_comments = myComments;


current.u_aom_analyst = gs.getUserID();





I could only test this in a background script with a fixed sys_id so you'll have to let me know if it works for you.


That didn't work either it's still blank. Someone mentioned that the variables aren't there yet when the record is created that it needs to be a business rule. Any ideas on how I would do something like that. I am horrible at scripting. I can manipulate something I find but that's the extent. Thanks a lot.