- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 08:52 AM
This is my current script:
<?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 ' + active);
var c = new GlideRecord("sc_cart");
c.addQuery("sys_id",jelly.sysparm_cart_name);
c.query();
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",active);
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>
In the log, I get the following:
07:50:39.838: : cart is 0a327da64f42320043b401f18110c751 and active is ed924c2e4f52320043b401f18110c73b
And on the page, I get:
Position id is *Undefined( var cart = jelly.sysparm_cart_name; var item = jelly.sysparm_active; gs.print('cart is ' + cart + ' and active is ' + active); var c = new GlideRecord("sc_cart"); c.addQuery("sys_id",jelly.sysparm_cart_name); c.query(); 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",active); 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; } } } )
I'm not sure why I can get the sys_ids from the URL without issue, but cannot get any results from my glide record queries...
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 09:12 AM
I found the bug - (besides the typos I pasted above and later fixed) - I was looking at the sys_id, when sysparm_cart_name is the "name" field on the cart. Changed that addQuery line and it's working now. Now to attempt the next steps...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 09:12 AM
I found the bug - (besides the typos I pasted above and later fixed) - I was looking at the sys_id, when sysparm_cart_name is the "name" field on the cart. Changed that addQuery line and it's working now. Now to attempt the next steps...