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

GlideDialogWindow getting field value and passing to UI page

E_19
Giga Expert

Hi All,

I have a UI Action on Incident that launches a GlideDialog Window and at present populates a list with service catalog item via UI page.

I now need to enhance this and get the company from the incident, pass this to the UI page and then only populate service catalog items that were created for the company.

The below returns the company sys_id should I or can I convert this to name? More difficult for me is how to pass/use the company variable in the UI page

function createStdChangeDialog() {

    var dialog = new GlideDialogWindow("dialog_standard_change_template");

    dialog.setTitle("Select a Standard Change Template");

    var comp = g_form.getValue('company');

    dialog.setPreference("target",   g_form.getTableName());

    dialog.setPreference("target_id", g_form.getUniqueValue());

  alert(comp);

    dialog.render();

}

Any suggestions greatly appreciated.

Ellie

1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi Ellie,



First you need to send the sys_id as a preference to the UI page.



function createStdChangeDialog() {


    var dialog = new GlideDialogWindow("dialog_standard_change_template");


    dialog.setTitle("Select a Standard Change Template");


    var comp = g_form.getValue('company');


    dialog.setPreference("target",   g_form.getTableName());


    dialog.setPreference("target_id", g_form.getUniqueValue());


        dialog.setPreference("company_id", comp);  


alert(comp);


    dialog.render();


}



then you use this in you query like this:


First you fetch the value like this and you do it inside the <evaluate> tags where you query is:


var comp = RP.getWindowProperties().get('company_id');



Then add it like this if the fieldname etc. is correct:


gr.addQuery('sc_cat_item_category', comp);


or if I get you fields correct, I guess it should be
gr.addQuery('company',comp);


I would doublecheck the query in a scripts - background or xplore to verify that with a correct company sys_id you get the right stuff back.



//Göran


View solution in original post

6 REPLIES 6

Chuck Tomasi
Tera Patron

You might find this helpful when using client scripts and reference fields if you want the display value.



If you are using the company as a reference in your UI page, however, you may want to actually stick with your sys_id value.



Get Display Value in Client Script for Reference field


Hi ellie,



If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you


Hi Chuck,



I think your second suggestion is the way to go but how would I add this to the below UI page code:



On the catalog item I added the company field so the second glide Record 'sc_cat_item_category' I am thinking to addQuery there with the comp variable that holds the company sys_id (see below in bold) but it breaks the code.




<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <g:evaluate var="jvar_categories" jelly="true" object="true">  


  var gr = new GlideRecord('sc_category');


  gr.addQuery('sc_catalog','797165294f463e40a1e260fe0310c74b');


  gr.addQuery('active', true);


  gr.query();


  var items = [];


  while(gr.next()) {


  var items_ = [];



  var gr_ = new GlideRecord('sc_cat_item_category');


  gr_.addQuery('sc_category', String(gr.sys_id));


                                                                                                                                                                    gr.addQuery('sc_cat_item_category'.company, comp);


  gr_.addQuery('sc_cat_item.active', true);


  gr_.query();



  while(gr_.next()) {


  items_.push({


  sys_id: String(gr_.sc_cat_item.sys_id),


  name: String(gr_.sc_cat_item.name)


  });


  }



  if(items_.length > 0) {


  items.push({


  sys_id: String(gr.sys_id),


  title: String(gr.title),


  items: items_


  });


  }


  }


  items;


  </g:evaluate>



Thanks,


Ellie


Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi Ellie,



First you need to send the sys_id as a preference to the UI page.



function createStdChangeDialog() {


    var dialog = new GlideDialogWindow("dialog_standard_change_template");


    dialog.setTitle("Select a Standard Change Template");


    var comp = g_form.getValue('company');


    dialog.setPreference("target",   g_form.getTableName());


    dialog.setPreference("target_id", g_form.getUniqueValue());


        dialog.setPreference("company_id", comp);  


alert(comp);


    dialog.render();


}



then you use this in you query like this:


First you fetch the value like this and you do it inside the <evaluate> tags where you query is:


var comp = RP.getWindowProperties().get('company_id');



Then add it like this if the fieldname etc. is correct:


gr.addQuery('sc_cat_item_category', comp);


or if I get you fields correct, I guess it should be
gr.addQuery('company',comp);


I would doublecheck the query in a scripts - background or xplore to verify that with a correct company sys_id you get the right stuff back.



//Göran