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

Could you please paste the code of your UI macro, then i can have a look on it.


Sure Ashish.. Here is 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">


 


<html>


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


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


  gs.log("inside macro " + uri);



  </g:evaluate>



  <button onclick="popupDispAttachments();"> Click Here to download the Attachment for New Catalog Item/Update Catalog Item</button>



<script>




function popupDispAttachments() {




  //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 = RP.getParameterValue('sysparm_id');


             


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


                      attach_window.setPreference('sysparm_query', query1);


  //Open the dialog window


  attach_window.render();




}


</script>


</html>


</j:jelly>


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.


Thank you so much Ashish.



Its working perfectly fine