- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 03:52 PM
Hello,
I am trying to mimic an incident form through a custom UI page and one of the requirements is that I receive a sys_id on the page load before the form is actually inserted into the database. A standard incident form follows this behavior where it will provide you a sys_id before it is truly written to the database. For those that are curious, I need the sys_id in order to create attachments on the record either before or after it is written to the table.
I have tried many approaches.... but my attempts have led me into using gr.newRecord() in the Jelly code in order to generate the sys_id without updating the database.
Current Jelly code looks like this :
<g:evaluate var="jvar_grSysId" object="true" copyToPhase2="true">
var gr = new GlideRecord('u_glodocs_work_order');
gr.newRecord();
gr.sys_id;
</g:evaluate>
This is great for getting a sys_id; however, it doesn't allow me to use the gr object anywhere else.
I have tried passing the gr object to the client script or processing script, but have been unsuccessful. From what I understand about Jelly... once the Jelly parser has finished, it does NOT pass objects from Jelly Code to Client Scripts (which makes sense, because that would essentially allow server side code to be used on client script context). I have also been unable to figure out how to pass the Jelly gr object to a process script or how to keep it alive in some type of namespace.
So the problem I am having, is how do I get a sys_id without creating a record AND more importantly, how do I update this sys_id when I am ready to save the information placed by the user on the UI page.
Attached is code that I have tried, but I have been getting errors due to conflicting sys_ids.
Processing Script that is giving two different sys_id's
var blah = new GlideRecord('incident'); blah.initialize(); blah.sys_id = application_sys_id; //app_sys_id passed in from form. blah.short_description = "This is a test inc from UI page cdekTest"; blah.update(); |
I also tried updating through a client script... and while it allowed me to update the record, and keep the sys_id.... it would write an informational message to the window that an error occurred.
Any help is appreciated on this.
Thanks,
~Constantine
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 11:05 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 09:54 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 09:54 PM
I hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 11:05 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2016 08:42 AM
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