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.

Display Variable Editor in Service Portal

reginabautista
Kilo Sage

Hi guys,

I have followed the workaround in the article in HI below...

ServiceNow KB: In Service Portal, the Variable Editor widget does not work with sc_task records and ...

I have then cloned the sp-variable-editor and embed it to the the Form cloned widget.

However the variables are still not displaying on the form.

Would you know what am I doing wrong?

find_real_file.png

1 ACCEPTED SOLUTION

reginabautista
Kilo Sage

Hi guys I have debugged the server script, the reason the variables were not displaying is because I was viewing a record created from a record producer. I had to change the code to get the record producer sysid rather than the catalog item:



var gr = new GlideRecord(data.table);


    if (gr.get(data.sys_id)) {


          var recordClassName = gr.getRecordClassName();


console.log('recordClassNamee=' +   recordClassName);


          if (recordClassName != data.table) {


                data.table = recordClassName


                gr = new GlideRecord(data.table);


                gr.get($sp.getParameter("sys_id"));


console.log('sysid=' + $sp.getParameter("sys_id"));


                }


          try {


            //var catItem = data.table == "sc_task" ? gr.request_item.cat_item : gr.cat_item;


var catItem = gr.u_record_producer;



console.log('gr.cat_item=' + gr.cat_item);


               


// data.sc_cat_item = $sp.getCatalogItem(catItem);


//regina added params to the getCAtalogItem as these were introduced after Istanbul 3a+


//catItem = '13ffd3dddbd28b40f82ada94ce9619e3';


data.sc_cat_item = $sp.getCatalogItem(catItem,false);


View solution in original post

13 REPLIES 13

reginabautista
Kilo Sage

Hi guys I have debugged the server script, the reason the variables were not displaying is because I was viewing a record created from a record producer. I had to change the code to get the record producer sysid rather than the catalog item:



var gr = new GlideRecord(data.table);


    if (gr.get(data.sys_id)) {


          var recordClassName = gr.getRecordClassName();


console.log('recordClassNamee=' +   recordClassName);


          if (recordClassName != data.table) {


                data.table = recordClassName


                gr = new GlideRecord(data.table);


                gr.get($sp.getParameter("sys_id"));


console.log('sysid=' + $sp.getParameter("sys_id"));


                }


          try {


            //var catItem = data.table == "sc_task" ? gr.request_item.cat_item : gr.cat_item;


var catItem = gr.u_record_producer;



console.log('gr.cat_item=' + gr.cat_item);


               


// data.sc_cat_item = $sp.getCatalogItem(catItem);


//regina added params to the getCAtalogItem as these were introduced after Istanbul 3a+


//catItem = '13ffd3dddbd28b40f82ada94ce9619e3';


data.sc_cat_item = $sp.getCatalogItem(catItem,false);


Hi Regina,


Thank you very much for the solution it worked very well. It worked for me - I just wanted to clarify how it worked:.



1. The formatter which displays the variables is located on the sp_ui_formatter table with a formatter of com_glideapp_servicecatalog_veditor


2. The fix you provided needs to be applied to the widget this formatter points to. Essentially var catItem variable needs to have the sys_id of the record producer in this case. This can be made to work with multiple tables if needed using if conditions for example:



if(data.table == "u_custom_table_1"){//So that variables can be displayed for the custom table you can have multiple if conditions for difference tables


var catItem = gr.u_cat_item; //A reference to the record producer the record is created from


  }


  else{


  var catItem = data.table == "sc_task" ? gr.request_item.cat_item : gr.cat_item;


  }


Hi Regina, 

 

I have same requirement , I need to display variable editor under request on portal. can you please suggest me.

 

Regards, 

Gari

emmahunt
Kilo Contributor

Hi there, I am on a Kingston instance and I am unable to get this working... I may be misunderstanding exactly what you had done. Could you please provide me with your updated code for the cloned sp-variable-editor widget?