Set choice list value from a UI Page

palmen
Tera Guru

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);

1 ACCEPTED SOLUTION

palmen
Tera Guru

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;


}


View solution in original post

14 REPLIES 14

Can you see the list view of the table and see if the value is getting saved? Do you have business rule or a client script that may be overriding the value before or after getting saved?


I can't find any businessrule or client script targeting the hold_reason field on incident table (it's an out of box field).


I've looked at the history for the incident, and there is nothing there about the hold_reason field has changed.


palmen
Tera Guru

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;


}


Community Alums
Not applicable

Any workaround that we have, because If I remove the ui_form tag it breaks my other functionality.

geoffcox
Giga Guru

Here is the html from my page.


I don't seem to have the advanced editor button at the moment, so I can't format it sensibly.



<g:ui_table>


<g:evaluate var="jvar_user_sysid" expression="RP.getWindowProperties().get('owner_id')" />


<g:evaluate var="jvar_user_name" expression="RP.getWindowProperties().get('owner_name')" />


<g:evaluate var="jvar_comment_text" expression="RP.getWindowProperties().get('comment_block')" />


<g:evaluate var="jvar_target_name" expression="RP.getWindowProperties().get('target_name')" />


<g:evaluate var="jvar_target_id" expression="RP.getWindowProperties().get('target_id')" />


<!-- owner field -->


<tr class="header">


  <td class="column_head">


      <span class="slushselect">Owner</span>


  </td>


</tr>


<tr>


  <td>


      <g2:ui_reference name="user" table="sys_user" value="${jvar_user_sysid}" displayvalue="${jvar_user_name}" />


  </td>


</tr>




<!-- target release field -->


<tr class="header">


  <td class="column_head">


      <span class="slushselect">Targeted Release</span>


  </td>


</tr>


<tr>


  <td>


      <g2:ui_reference name="QUERY:u_released=false" table="u_tools_releases" value="${jvar_target_id}" displayvalue="${jvar_target_name}" />


  </td>


</tr>




<!-- comment field -->


<tr class="header">


  <td class="column_head">


        Comment:


  </td>


</tr>


<tr>


  <td>


        <textarea id="issue_comments" rows="3" cols="65" wrap="soft">${jvar_comment_text}</textarea>


  </td>


</tr>


<tr><td>


<!-- twin SELECTS -->


<div align="center">


<g:dialog_button onclick="return onSubmit();" name="ok_button" id="map_button">${gs.getMessage('OK')}</g:dialog_button>


<g:dialog_button onclick="cancel();" name="cancel_button" id="cancel_button">${gs.getMessage('Cancel')}</g:dialog_button>


</div>


</td></tr>


</g:ui_table>


<script>


var comment_contents = document.getElementById('issue_comments');


if (comment_contents.innerHTML == ' ') {


      comment_contents.innerHTML = '';


}


</script>