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

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

Thats because you do not have any field called sysapproval in change request table.




Write a On before Insert BR on change task table with the below script(of course with proper conditions)




var varArray='';


var variables = new GlideRecord('question_answer');


variables.addQuery('table_sys_id', current.change_request);


variables.query();


while(variables.next())


{


varArray.push(variables.question.getDisplayValue()+" "+variables.value);


}


current.description=varArray.join();






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.


Hi Erik,



Your code works like a charm, however do we know how I can get the current record's table_sys_id? is that possible?



Thanks,


Srini


the gr object will contain the table_sys_id at gr.table_sys_id.   call gr.table_sys_id in the while loop as you see fit.  



i'll use this as an opportunity to plug xplore.   terrific tool to view the contents of an object.   scripts - background?   yeah, i remember when i had to use that.   xplore ftw!


mikereaves
Tera Expert

Do you know if there is an equivalent table for sc_req_item? As question_answer is to record producer     _______________ is to sc_req_item