Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to loop all Record producer variables in the record producer script.

nj70
Kilo Contributor

I have create a record producer for change_request.
In this I am also creating change task for this change request.

So here I want to display all the variables in the record producer in change task description field like " <variable name1 >: <variable Value1>, <variable name2>: <variable Value3>}"

I tried some script by querying from "question_answer" table to get the variable details but It is not giving the variables.

Is there any way to loop all the variables.  


Thanks In advance..

1 ACCEPTED SOLUTION

ewj
Kilo Expert

try this:


var gr = new GlideRecord('question_answer');


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


gr.query();


while (gr.next()) {


  if (gr.value) { //exclude questions with empty values


  gs.print(gr.question.getDisplayValue() + ":   " + gr.value); //display question and answer


  }


}



should return something like:



*** Script: Please describe your issue below: user entered description


*** Script: Open on behalf of this user: 7839639120196100636f41ee6e8383d6


*** Script: Short description (Subject Line): user entered short description



will take a bit more work if you have referenced values.


View solution in original post

11 REPLIES 11

values for ritm variables are stored in the ritm object (sc_req_item.variables).   the variable name is there as well.   if you want the question text, one would need to cross reference the variable name against the item_option_new table.


rlatorre
Kilo Sage

Have you tried adding the "Change Variable Editor" to the form?