bernyalvarado
Mega Sage

Hi Constantine,



A Jelly code is basically server side code which intent is primarily to process some logic on the server side and produce a resultant client side html/code that can be rendered/understood by the browser. With that in mind, one option that you have is the following:



a) create a new incident on your jelly. It can be something as simple as:



var blah = new GlideRecord('incident');


blah.initialize();


blah.short_description = "more blah";


var sysId = blah.insert();



b) you will then add the sys_id as the value of a hidden html tag within your code. That way the actual value of the sys_id will be available at your client script code. keep in mind to set an id to the hidden html tag so that you can reference it with something like gel('id_of_the_element');



c) use GlideAjax within your Client code to invoke server side functions in an efficient way while your user is interacting with your ui page.



Thanks,


Berny


bernyalvarado
Mega Sage

I hope this helps


Gurpreet07
Mega Sage

Hi Constantine,


Solution Provided by Berny should work for you but if still you need to generate sys_id earliest (before insert) then   you could make use of setNewGuid() method


GlideRecord - ServiceNow Wiki


View solution in original post

Thank you so much Singh. The setNewGuid() did exactly what I needed. I have posted my final code solution based on your answer in case someone else finds this useful.


UI Page :


Jelly Code :

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


<g:evaluate var="jvar_grSysId" object="true">


    // Create a new Record, but do not save it to the database.


  var gr = new GlideRecord('incident');


  gr.newRecord();


  gr.sys_id;


</g:evaluate>


<p> The sys_id is : ${jvar_grSysId} </p>


  <input type="hidden" name="application_sys_id" value="${jvar_grSysId}"/>


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


</g:ui_form>


</j:jelly>



Processing Script :

// Get sys_id of new record that hasn't been committed to the database yet. Save/commit the record to the database.


var blah = new GlideRecord('incident');


blah.setNewGuidValue(application_sys_id);


blah.short_description = "This is a test inc from UI page";


blah.update();



Thanks,


~Constantine


Hi Constantine,



I do have a same requirement. I got a help from your code posted but it is giving me 'not authorized' message whenever I press the OK button.



Please let me know if you have any suggestions on that.



Thanks,


Paromita