- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2016 08:50 AM
I'm trying to set a value in a choice list field (On Hold reason) on the incident form with the value I select from a UI Page.
I'm new to jelly and these kind of stuff so I assume it's something easy I'm missing here.
Everything works fine, except the new value is never saved.
I get the value and it's returned to the incident form.
The page reloads and the previous value is still present in the "On hold reason" field. Before it reloads I can see the new value there for a split second
This is what I'm working with
A Ui Action displaying a glide dialog window
function onHold2(){
var gdw = new GlideDialogWindow('on_hold_reason');
gdw.setTitle('Chose an On hold reason');
gdw.setSize(400,300);
gdw.setPreference('title', 'A New Title');
gdw.render();
}
My UI Page looks like this
<?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:ui_choicelist name='HoldReason' table='incident' field='hold_reason' />
<br />
<br />
<g:dialog_buttons_ok_cancel ok="return updateOnHold()"/>
</g:ui_form>
</j:jelly>
Client script on the UI Page
function updateOnHold() {
//Gets called if the 'OK' dialog button is clicked
GlideDialogWindow.get().destroy(); //Close the dialog window
var reason = gel('HoldReason').value;
g_form.setValue('hold_reason', reason); //Set 'On Hold Reason' field with the chosen reason
g_form.save();
}
Processing script on UI Page
// redirect back
var urlOnStack = GlideSession.get().getStack().bottom();
response.sendRedirect(urlOnStack);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 09:17 AM
We've found out what is causing the value not to be saved, it's the g:ui_form tag in the UI Page, if we remove them everything works fine.
No idea why it's like that, but in some way it seems like the g:ui_form does a reload or save the previous value when you perss the OK button.
The code we are using now is
UI ACTION
function onHold2(){
var d = new GlideModal('on_hold_reason', false);
d.setTitle('Chose an On hold reason');
d.setPreference('title', 'A New Title');
d.setSize(400,300);
d.render();
}
UI PAGE
<?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_choicelist name='HoldReason' table='incident' field='hold_reason' />
<br />
<br />
<g:dialog_buttons_ok_cancel ok="return updateOnHold()"/>
</j:jelly>
UI PAGE Client Script
function updateOnHold() {
var reason = gel('HoldReason').value;
g_form.setValue('hold_reason', reason);//Set 'On Hold Reason' field with the chosen reason
g_form.save();
GlideDialogWindow.get().destroy(); //Close the dialog window
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2016 01:56 PM
Your function updateOnHold doesn't make much sense?
I'm not sure what form the element "HoldReason" is on. I suspect it's on your dialog window, but you just destroyed the dialog window before you tried to load the HoldReason. Also, your updateOnHold function isn't returning true.
Having said that, I think calls to "g_form", even from the dialog window, actually address the underlying glide form.
My dialog boxes use "document.getElementByID('<element name') to retrieve values from elements on the dialog window, and they use g_form.setValue('<field name>',<value>) to set the fields on the underlying form.
Then I call gsftSubmit(gel('sysverb_update_and_stay')) so that the changes on the underlying form will be saved upon return. Maybe this is the same as g_form.save(), but I'm not sure.
The the last thing I do before returning "true" is to destroy the dialog window.
So here, for example, is a fully working onSubmit function for a dialog box that is asking the user for three things: A user, a release, and some comments:
function onSubmit() {
var ic = document.getElementById('issue_comments');
var iu = document.getElementById('user');
var tr = document.getElementById('QUERY:u_released=false');
if((iu.value == '') || (iu.value == 'undefined')) {
alert("Please select a user.");
return false;
}
else {
g_form.setValue('assigned_to',iu.value);
g_form.setValue('u_targeted_release',tr.value);
if (ic.value.length > 1) {
g_form.setValue('u_comments',ic.value+'');
}
g_form.setValue('u_status','Open');
gsftSubmit(gel('sysverb_update_and_stay'));
GlideDialogWindow.get().destroy();
return true;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2016 01:37 AM
I've tried with the following but with the same result, the field value is set but never saved
function updateOnHold() {
//var reason = gel('HoldReason').value;
var reason = document.getElementById('HoldReason');
alert(reason.value);
g_form.setValue('hold_reason', reason.value); //Set 'On Hold Reason' field with the chosen reason
gsftSubmit(gel('sysverb_update_and_stay'));
GlideDialogWindow.get().destroy();
return true;
}
The alert is showing 2 (which is what I expect)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2016 08:51 AM
Can you share the html code as well?
Maybe there is something different between how it works with a choice list compared to text field or reference field?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2016 02:07 PM
I don't think you need g_form.save() in the client script. Take that out and see if it works