In UI Macro how to get fetch a value from url

kiranjyothi
Tera Contributor

Hi All,

Anybody has an idea on how to pull values from url into a UI macro.

We have a UI macro which downloads all attachments attached to that particular catalog item.

https://instance.com/com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=ce5985866f3c4200a07...

from above url I want to fetch the sysparm_id value into a ui macro.

function popupDispAttachments() {

                      //var item_id = g_form.getParameter("sysparm_id");

                      //gs.addInfoMessage("sysparm id is": +item_id);

                      //Initialize the GlideDialogWindow

                      var attach_window = new GlideDialogWindow('display_attachment');

                      attach_window.setTitle('Download Attachment for New Catalog Item/Update Catalog Item');

                      attach_window.setPreference('table', 'sys_attachment_list');

                      attach_window.setPreference('sysparm_view', 'default');

                      //Set the table to display

                      //var num = g_form.getValue('number');

  var item_id = getParmVal('sysparm_id');

                      var query1 = 'table_name=sc_cat_item';

                      attach_window.setPreference('sysparm_query', query1);

                      //Open the dialog window

                      attach_window.render();

                      function getParmVal(name) {

  gs.log('Inside the UI Macro Download Attachment for Catalog Item');

                              var url = document.URL.parseQuery();

                              if (url[name]) {

                                      return decodeURI(url[name]);

                              } else {

                                      return;

                              }

                      }

              }

1 ACCEPTED SOLUTION

Try below


var id = '${RP.getParameterValue('sysparm_id')}';


alert(id); // alert is giving the value of sysparm_id


attach_window.setPreference('sysparm_query', id);


And in the UI Page you can create the encoded query with sys_id.


View solution in original post

8 REPLIES 8

Ashish Kumar Ag
Kilo Guru

Use below inside UI macro.



<g:evaluate var="jvar_uri">


var uri = RP.getParameterValue('sysparm_id');


</g:evaluate>



you can use the variable as ${jvar_uri}


Thanks for the response Ashish.



As you mentioned fetched the sysparm_id value into jvar_uri and could see that it is fetching correct sysid. However after fetching this value, I need to use it in function PopupDispAttachments, which is not happening now.



var query1 = 'table_name=sc_cat_item^table_sys_id=';


                      attach_window.setPreference('sysparm_query', query1);



Here for query1 table_sys_id, I need to assign the value fetched from URL(jvar_uri). I tried below ways but none seems to be working. How to use the value fetched from url into this query?



var query1 = 'table_name=sc_cat_item^table_sys_id='+${jvar_uri};


var query1 = 'table_name=sc_cat_item^table_sys_id='+uri;


if you are using the variable inside the <script> tag then try below



var dd = '$[jvar_uri]';


var query1 = 'table_name=sc_cat_item^table_sys_id='+dd;



Please Mark correct/Helpful if it helps you resolve the issue.


I tried that, but no luck.



Is there anyway to pass jar_uri   as an argument while calling the function?