Call URL from ui macro

eashwar
Tera Contributor

Folks,

I am trying to generate a simple URL in UI macro and call. its failing sysparam needs a demiliter.

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">

    <j:set var="jvar_n" value="add_me_${ref}"/>

    <span id="${jvar_n}" onclick="addMe('${ref}')" title="Add me" alt="Add me" tabindex="0" class="btn btn-default icon-default-knowledge-base">

          <span class="sr-only">Add me</span>

    </span>

  <script>

          function addMe() {

      var url = "https://"+window.location.hostname.toString()+"/kb_knowledge.do?sys_id=-1&amp;sysparam_query=short_descriptionLIKEMAJOR";

  window.open(url, "_blank");

      return false;

          }

    </script>

</j:jelly>

How to call a url with param value ?

Thank you,

Eashwar Elumalai

1 ACCEPTED SOLUTION

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

Sorry the way I was doing it (i.e. based on the ui macro) required the form to be saved before it would work.   LIkely what was the issue.   This version does not:



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


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


    <j:set var="jvar_n" value="add_me_${ref}"/>


    <span id="${jvar_n}" onclick="addMe('${ref}')" title="Add me" alt="Add me" tabindex="0" class="btn btn-default icon-default-knowledge-base">


          <span class="sr-only">Add me</span>


    </span>




  <script>


  function addMe(reference)


  {


      window.open('$knowledge.do#/search?query=' + encodeURI(g_form.getValue('short_description')) + '$[AMP]order=default');


  }


  </script>



</j:jelly>


View solution in original post

22 REPLIES 22

i tried doing that but it not give me the result which business was requiring. So build this in UI action and it worked fine and now business wants it as a icon functionality.


Joe McCarty1
ServiceNow Employee
ServiceNow Employee

This was working on my instance on the kb_submission form.   I commented out the one version of knowledge search.   Depending on whether you are on v2 or v3 you may want to switch.



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


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


    <j:set var="jvar_n" value="add_me_${ref}"/>


    <span id="${jvar_n}" onclick="addMe('${ref}')" title="Add me" alt="Add me" tabindex="0" class="btn btn-default icon-default-knowledge-base">


          <span class="sr-only">Add me</span>


    </span>




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


            var url = '';


  gs.info('JDM - ' + jelly.sys_id);


  var inc = new GlideRecord('kb_submission');


  if (inc.get(jelly.sys_id)) {


            /*if (inc.short_description == "") {


                      url = gs.getProperty('glide.servlet.uri') + "kb_find.do?sysparm_search=" + encodeURI(inc.short_description) + "$[AMP]sysparm_operator=IR_OR_QUERY$[AMP]sysparm_order=relevancy$[AMP]sysparm_stack=no$[AMP]sysparm_query=sys_id!=" + inc.sys_id;


            } else {*/


                url = gs.getProperty('glide.servlet.uri') + '$knowledge.do#/search?query=' + encodeURI(inc.short_description) + '$[AMP]order=default';


            //}


  }


            url + '';


</g:evaluate>



  <script>


  function addMe(reference)


  {


      window.open("${jvar_url}");


  }


  </script>



</j:jelly>


Screen Shot 2017-02-22 at 7.22.57 PM.png


Screen Shot 2017-02-22 at 7.22.53 PM.png


eashwar
Tera Contributor

Do you know which UI macro "knowledge_search=true" is referring to ?


I am unable to find it


eashwar
Tera Contributor

what attribute value are you specifying. its opening up a blank page for me


eashwar
Tera Contributor

can you send me the screen shot of attribute value and ui macro ?