Update multiple tickets from UI Page

A Oliver
Kilo Explorer

Morning all,

I'm trying to update multiple tickets from a UI page. At present, for testing I'm just trying to add comments to multiple tickets with the click of one button, I think I can work out the rest from there of where I want to go with this. Just Jelly loses me.

So say for now the HTML portion is for now:

<g:ui_form>  

<input type="hidden" name="incident_id" value="TICKET1SYSID"/>  

<textarea id="comments" name="comments"></textarea>  

<g:dialog_buttons_ok_cancel ok="return true" />  

</g:ui_form>

<g:ui_form>

<input type="hidden" name="incident_id" value="TICKET2SYSID"/>  

<textarea id="comments" name="comments"></textarea>

<g:dialog_buttons_ok_cancel ok="return true" />

</g:ui_form>

Processing script example:

var inc = new GlideRecord('incident');  

inc.get(incident_id);  

inc.comments  = comments;  

inc.update();  

var urlOnStack = GlideSession.get().getStack().bottom();

response.sendRedirect(urlOnStack);

How do you split this out to be 1 button to save updates to all tickets.

For example, I want 1 UI page with multiple text inputs, that I'll have 1 button to save all - then it updates all of those tickets.

Hope this makes sense. Any pointers as to what to look at I'll much appreciate - google has me at a loss at present.

1 ACCEPTED SOLUTION

Hi



I modified your HTML a bit and dropped the jvar_i and its working in my end. In line



<g2:evaluate jelly="true">  


        var rec = new GlideRecord('planned_task');  


        rec.addQuery('active', true);  


        rec.addQuery('assigned_to', "X");  


        rec.query();  


        var count = 0;


</g2:evaluate>  




<j2:while test="$[rec.next()]">  


        <p>$[rec.number] </p>  


        <g2:evaluate>count++;</g2:evaluate>


        <input type="hidden" name="planned_$[count.toFixed()]" id="planned_$[count.toFixed()]" value="$[rec.getUniqueValue()]"/>  


        <textarea id="comments_$[count.toFixed()]" name="comments_$[count.toFixed()]"></textarea>    


</j2:while>  



<input type="hidden" name="rowCount" id="rowCount" value="$[rec.getRowCount()]"/>  


<g:ui_form><g:dialog_buttons_ok_cancel ok="return true" /></g:ui_form>



For some reason the "count" was printet as xxx.0 so thats the reason i added the "toFixed()" to it


View solution in original post

10 REPLIES 10

larstange
Mega Sage

Sorry - the part of my example that says



<j:set var="jvar_i" value="0" />



Needs to be before the rest of the code, and



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



Needs to be last


I fear I'm missing something fundamental   - sorry.



<g2:evaluate jelly="true">


var rec = new GlideRecord('planned_task');


rec.addQuery('active', true);


rec.addQuery('assigned_to', "X");


rec.query();



</g2:evaluate>



<j:set var="jvar_i" value="0" />


<j2:while test="$[rec.next()]">


<g2:evaluate var="jvar_i" expression="++jvar_i"/>


<p>$[rec.number] </p>


<input type="hidden" name="planned_$[jvar_i]" id="planned_$[jvar_i]" value="$[rec.getUniqueValue()]"/>


<textarea id="comments_$[jvar_i]" name="comments_$[jvar_i]"></textarea>


</j2:while>



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



<g:ui_form><g:dialog_buttons_ok_cancel ok="return true" /></g:ui_form>










The Rec query is successfully returning tasks.



Processing:



var numPlanned = eval(rowCount);



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


        var planned_id = eval("planned_" + i);


        var comments = eval("comments_" + i);



        var inc = new GlideRecord('planned_task');  


        inc.get(planned_id);  


        inc.comments  = comments;  


        inc.update();  


}


        var urlOnStack = GlideSession.get().getStack().bottom();


        response.sendRedirect(urlOnStack);






I still get the log error and no comment in the tasks.


larstange
Mega Sage

Try moving the jvar_i to phase 2 instead



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



Extensions to Jelly Syntax - ServiceNow Wiki


Thanks for the patience.



Still no joy. I've tried switching phases, moving where the set happens and even adding phase brackets to the variable in the evaluate and adding jelly="true". Nothing seems to do the trick.


Hi



I modified your HTML a bit and dropped the jvar_i and its working in my end. In line



<g2:evaluate jelly="true">  


        var rec = new GlideRecord('planned_task');  


        rec.addQuery('active', true);  


        rec.addQuery('assigned_to', "X");  


        rec.query();  


        var count = 0;


</g2:evaluate>  




<j2:while test="$[rec.next()]">  


        <p>$[rec.number] </p>  


        <g2:evaluate>count++;</g2:evaluate>


        <input type="hidden" name="planned_$[count.toFixed()]" id="planned_$[count.toFixed()]" value="$[rec.getUniqueValue()]"/>  


        <textarea id="comments_$[count.toFixed()]" name="comments_$[count.toFixed()]"></textarea>    


</j2:while>  



<input type="hidden" name="rowCount" id="rowCount" value="$[rec.getRowCount()]"/>  


<g:ui_form><g:dialog_buttons_ok_cancel ok="return true" /></g:ui_form>



For some reason the "count" was printet as xxx.0 so thats the reason i added the "toFixed()" to it