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

Hi



In your HTML portion you need to save a count of how many Incidents you are displaying



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



You then also need to generate the hidden inputs for each incident, so they get a different ID



First get the relevant incidents


<g2:evaluate jelly="true">


var incidentGr = new GlideRecord("incident");


incidentGr.addQuery('some query to find the incidents');


incidentGr.query();


</g2:evaluate)



Then generate the hidden inputs


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


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


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


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


</j2:while>



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



Now you can process the hidden inputs in you processing script



var numIncidents = eval(rowCount);



for (var i = 0; i<numIncidents, i++) {


        var incident_id = eval("incident_" + i);


        var inc = new GlideRecord('incident');    


        inc.get(incident_id);    


        inc.comments  = comments;    


        inc.update();    


}


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


        response.sendRedirect(urlOnStack);


Thanks Lars! I'm having a go at popping that into my example this side now.



Would you say I'm better off doing any queries within the evaluate tags from within the HTML portion, rather than doing an Ajax call from the client portion then?


larstange
Mega Sage

Hi



Its a bit hard to answer as I don't know the background of what you are doing and what it has to be used for.



But Jelly is basically a server side HTML page generation language - like php or ASP.


So normally you would generate it all server side and not use client scripts/AJAX/DOM manipulation


Cool, makes sense.



Hopefully just one last question then... (Trying to work it out myself as much as I can).



  inc.comments  = comments; From the processing script - if I pop a text area to generate under the hidden input with the comments id/name, even if I add the $[jvar_i] to it as with the input name and pull that through in the processing script, I still cant get the comment per ticket to end up in the appropriate ticket. If that makes sense?




EDIT: Actually I'm getting a log error - org.mozilla.javascript.EcmaError: "jvar_i" is not defined.==> 1: ++jvar_i