UI Page Processing Script and HTML/Jelly/Javascript Array Variables "undefined"

tobrien
Kilo Guru

Hi Everyone !

I have a UI PAGE (which has been working flawlessly for years!) that creates an HTML table where each row is retrieved from GlideRecord data. Each row has an ID that ends with a increasing JVAR. 

item is the GlideRecord; 

<g2:evaluate var="jvar_i" expression="jvar_i = -1;" />
<j2:while test="$[item.next()]">
<g2:evaluate var="jvar_i" expression="++jvar_i;" />

Then further down ... there is a CheckBox leftmost on each row

<input type="checkbox" class="checkbox" id="item_received_$[jvar_i]" name="item_received_$[jvar_i]" />

 

We have had no SNowy upgrades to blame this on but until just yesterday I was able to access the CheckBoxes in the Processing Script using...

for (var i = 0; i < numRows; ++i) {

    var checked = false;
    try {
       checked = eval("item_received_" + i);
    }
    catch (e) {

        gs.log('checked error: ' + e.message, 'TOB_RCV');

     }

}

If I GoogleInspect the HTML I find that each row has the ID="item_received_nn" where nn was incremented for each row. BUT that catch() in the Processing Script returns item_received_nn is undefined for every row !

Further investigation shows that ANY $[jvar_i] built array is undefined, but non-arrays (i.e. any simple variable with no $[ ] ) work as expected. 

Should I be using some other mechanism to create or evaluate an array from the processing script?

 

Thanks !

tony

 

{ EDIT } 

 

Here is the briefest means to reproduce this error in the gs.log():

HTML ==>

<?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:ui_form>

    <j2:set var="jvar_i" value ="1" />

    <input type="hidden" name="rowCount" id="rowCount_$[jvar_i]" value="$[jvar_i]"/>

    <button type="submit" id="submit_popup" name="submit_popup" onclick="return submitChanges();">${gs.getMessage('OK')}</button>

</g:ui_form>
</j:jelly>

 

Client script ==>

function submitChanges() {
return true;
}

Processing Script ==>

try {

   var y = eval("rowCount_1");
   gs.log(y , 'TOB_UI');


} catch(e) {
   gs.log(e.message, 'TOB_UI');
}

 

 

 

1 ACCEPTED SOLUTION

ServiceNow Tec2
Mega Sage
This has been resolved by ServiceNow Technical Support. Please refer to KB0841016 for more information.

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@tobrien 

Can you share the entire HTML, client script and processing script for better debugging

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Good Morning, Mr. Ankur !

I have edited the question to show the smallest amount of html and scripts that reproduce the issue ...

 

Please see everything after the {EDIT}

 

Thanks for helping out on this!

 

tony

ServiceNow Tec2
Mega Sage
This has been resolved by ServiceNow Technical Support. Please refer to KB0841016 for more information.