Need to call RITM Variable from a Client UI action

anurag92
Kilo Sage

Hi,

I am stuck in a tricky situation. I have a button on RITM form that opens a Service Catalog in a Dialog Window. I want variables in Window to be populated by variables of RITM.

UI Action is Client and has below code to get variables from RITM, but that does not work.

var z = current.variables.u_customer_name;

  var x = g_form.getValue('number');

var gr = new GlideRecord("sc_req_item");

gr.addQuery('number', y);

gr.query();

if (gr.next()) {

    y = gr.variables.u_customer_name;

}

z and y are returning Undefined values. Is there any other way to call RITM variables from UI action?

I did a lot of research on this, but couldn't find a solution.

The form looks like this:

find_real_file.png

1 ACCEPTED SOLUTION

I figured this out. It's not possible to call variables directly from client UI action, so I had to use a GlideAjax to get the variable values.


View solution in original post

5 REPLIES 5

Gopinath Laksh1
Kilo Contributor

Hi Anuraj,



Can please provide more clarification on the script..



Customer name is reference field or just string. In the above code, the y denotes number or customer name because first you have used y as number then assigning it to a customer name.



Thanks


Gopinath L


Hi,



Yes that's my bad, look at the updated (incomplete) code:



function cloneRequest() {


  //var z = current.variables.u_customer_name; //saving variable value using current


  var x = g_form.getValue('number');


var gr = new GlideRecord("sc_req_item");


gr.addQuery('number', x);


gr.query();


if (gr.next()) {


  var y = gr.variables.u_customer_name; //saving variable value using gliderecord object


}


var changeDialog = new GlideDialogForm('Catalog Form','com.glideapp.servicecatalog_cat_item_view');


  changeDialog.addParm('sysparm_id', 'bb19c616dba5220044e4fabdbf961924');


  changeDialog.setLoadCallback(function(iframeDoc) {


var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;


  var interval;


  var count = 0;


  interval = setInterval(function() {


  try {


  if (dialogFrame.g_form) {



  dialogFrame.g_form.setValue('u_customer_name',y); //setting value using y


  //dialogFrame.g_form.setValue('u_customer_name',x); // setting value using x



u_customer_name is a variable from RITM that has to be saved on pop-up window form.


I figured this out. It's not possible to call variables directly from client UI action, so I had to use a GlideAjax to get the variable values.


Hello, 

 

Can you help me out with the below script using GlideAjax? I'm trying to call the variable value for that but I'm not successful.

var a = new GlideRecord('sc_req_item');
a.addQuery('sitename','current.variable.sitename');
a.query();
while(a.next())
{
b = a.variable.sitename;
gs.print(b);
}