UI Macro - Getting the input into the g2:evaluate and then nesting g2:evaluate inside table build

kristenankeny
Tera Guru

To preface, I got really frustrated and sat down and watched all three of the intro to jelly videos referenced in the wiki. I think what I want is probably simple (as simple as jelly can be...), but I'm stumped and was wondering if someone could help.

I have a Catalog Form that will be shown from a "New Hire" order guide when a user selects a pre-defined position (extension of the request table). On this catalog item, I want to summarize all of the required items (extension of the sc_req_item table) related to the position they selected. My plan right now is outlined in the below script (mostly comments right now, was trying to think through it logically).

In order to get the value of the position sys_id into my macro, I had to add a client script to my catalog item that calls the client script inside this ui macro to set an input field to the sys_id. This works without issue.

My questions are:

  • How do I get the data in the input field into my scripts (was planning to use g2:evaluate because the position changes and they can change the position selected prior to submission)?
  • Can I nest doing the g2:evaluate and populating/building the table? As noted in the comments in the script, I want two columns: Requested item and Details. Requested item will just contain the form name, but Details will contain all the variables (that meet certain if statements) in a list. There are three loops in my table build: Loop through the required items, loop through each required item's variables, and if the variable is an array, loop through the variable array. For each required item loop, I need to start a new row, for the variable loops, they will happen to populate a cell in that single row.

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

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

  <input type="text" id="position_id" name="position_id" value=""/>

  <!--Include the scripts for setPosition -->

  <script>

  function setPosition(text){

  $j("#position_id").val(text);

  }

  </script>

  <!--Create a table with headers: Requested item and Details - phase 1-->

  <h2>This position includes the following requested items</h2>

  <table style="width:50%">

  <thead>

  <tr>

  <th>Requested item</th>

  <th>Details</th>

  </tr>

  </thead>

  <!--Query the required item table for ris related to the position received - phase2-->

  <tbody>

  </tbody>

  <!--For each required item, print the name in the first table field and then find the variable set-->

  <!--For each variable, if it matches the criteria to be included, print the getDisplayValue (vs.get(i).getDisplayValue())-->

  <!--Within the for each variable, check if it is an array and not type two. If this matches, print the vs.get(i).getLabel() with a colon and then a break-->

  <!--Within the array if statement, do a for each in the array and print array[a] with a break-->

  <!--within the for each variable, if not an array, print the label and display value with a break-->

  </table>

</j:jelly>

1 ACCEPTED SOLUTION

After taking a completely different approach, this is my current script I'm starting with and it returns the sys_id of the position so that I can hopefully use that in my scripts to get the required items.



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


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





  <g2:evaluate var="jvar_position_id" jelly="true">



  var cart = jelly.sysparm_cart_name;


  var item = jelly.sysparm_active;


  gs.print('cart is ' + cart + ' and active is ' + item);


  var c = new GlideRecord('sc_cart');


  c.addQuery('name',cart);


  c.query();


  gs.print('cart is' + c.sys_id);


  if(c.next()){


  gs.print('Found the cart');


  var ci = new GlideRecord('sc_cart_item');


  ci.addQuery('cart',c.sys_id);


  ci.addQuery('cat_item',item);


  ci.query();


  if(ci.next()){


  gs.print('Found the cart item');


  var io = new GlideRecord('sc_item_option');


  io.addQuery('cart_item',ci.sys_id);


  io.addQuery('item_option_new.name','position');


  io.query();


  if(io.next()){


  gs.print('Found the position variable');


  var position_id = io.value;


  gs.print('Position id is ' + position_id);


  position_id;


  }


  }


  }




  </g2:evaluate>



  <p>Position id is $[jvar_position_id]</p>



</j:jelly>


View solution in original post

6 REPLIES 6

Gurpreet07
Mega Sage

Don't understand your requirement correctly but the value of any input element can be obtained by javascript.


var val = document.getElementById('possition_id').value ;


alert(val);


Unfortunately document comes back undefined in debugging.


Can you please paste the code?


I've actually completely scrapped what I did and am trying another approach.



This is the current script, but I'm getting an error and cannot figure out why:


<?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_position_id" jelly="true">


  gs.print('>>>>>>>>>>>>CART NAME IS ' + ${sysparm_cart_name});


  var c = new GlideRecord('sc_cart');


  c.addQuery('sys_id',${sysparm_cart_name});


  c.query();


  if(c.next()){


  var ci = new GlideRecord('sc_cart_item');


  ci.addQuery('cart',c.sys_id);


  ci.addQuery('cat_item',${sysparm_active});


  ci.query();


  if(ci.next()){


  var io = new GlideRecord('sc_item_option');


  io.addQuery('cart_item',ci.sys_id);


  io.addQuery('item_option_new.name','position');


  io.query();


  if(io.next()){


  var position_id = io.value;


  gs.print('>>>>>>>>>>>>>>Position id is: ' + position_id);


  position_id;


  }


  }


  }


  </g:evaluate>



</j:jelly>




This is the bug:



06:26:21.674: Javascript compiler exception: missing ) after argument list (ftp://gsft_database/required_items.6; line 4) in: gs.print('>>>>>>>>>>>>CART NAME IS ' + jelly.sysparm_cart_name); var c = new GlideRecord('sc_cart'); c.addQuery('sys_id',0a327da64f42320043b401f18110c751); c.query(); if(c.next()){ var ci = new GlideRecord('sc_cart_item'); ci.addQuery('cart',c.sys_id); ci.addQuery('cat_item',ed924c2e4f52320043b401f18110c73b); ci.query(); if(ci.next()){ var io = new GlideRecord('sc_item_option'); io.addQuery('cart_item',ci.sys_id); io.addQuery('item_option_new.name','position...



Also, every time I try to use g2:evaluate, it prints it on the page instead of runs it.... why?