UI Action to update catalog variables value in request Item

SHA3
Giga Expert

I have created a UI action to fetch a field in RITM catalog variables and show in Glidedialogwindow and when user enters value it needs to be updated in the field.

Using below steps:

Ui Action of client type:

function updateInput(){

  var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;

  var dialog = new dialogClass("change_value_popup");

  //dialog.setWidth("800");

  dialog.setTitle(getMessage("Change the value with appropriate"));

  dialog.setPreference('sysparm_sys_id', g_form.getUniqueValue());

  dialog.render(); //Open the dialog.

}

===========================================================================================================

UI Page XML:

<?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:evaluate var="group_mailbox"

      expression="RP.getWindowProperties().get('current.variables.mailbox')" />

  <tr>

                      <td class="label">

                              ${gs.getMessage('Please provide appropriate value:')}

                      </td>

                      <td>

                             

  <g:ui_input_field name="mailbox_name" id="mailbox_name" label="Group Mailbox Name" value="${group_mailbox}"

                      />

    </td>

                </tr>

                <tr>

                      <td>

                              <g:dialog_button id="submit_button" type="submit"

                                onclick="entervalue('${sysparm_id}', this)">${gs.getMessage('Submit')}</g:dialog_button>

                              <g:dialog_button id="cancel_button" type="submit"

                                onclick="closevalueWindow(this)">${gs.getMessage('Cancel')}</g:dialog_button>

                      </td>

                </tr>

      </j:jelly>

Ui Page Client Script:

function closevalueWindow() {

  GlideDialogWindow.get().destroy();

}

function entervalue() {var groupmailbox = gel("mailbox_name").value;

  alert(groupmailbox);

    if (groupmailbox == "") {

          alert("Please enter your value before submitting.");

          return false;

    }

    var req_item = g_form.getUniqueValue();

  alert(req_item);

  var ga = new GlideAjax('AutomationUtils');

  ga.addParam('sysparm_name', 'Changevalue');

  ga.addParam('sysparm_sysid',req_item);

  ga.addParam('sysparm_groupmailbox',groupmailbox);

  ga.getXMLAnswer(getresponse);

  function getresponse(answer){

  closevalueWindow();

  g_form.save();

  }

}

==============================================

Script Include function:

Changevalue: function() {

  var mailbox = this.getParameter('sysparm_groupmailbox');

  var sysid = this.getParameter('sysparm_sysid');

  var req = new GlideRecord('sc_req_item');

              req.get('sysid');

  req.variables.mailbox = mailbox;

  req.update();

  return true;

  new Workflow().broadcastEventToCurrentsContexts(req, 'update', null);

  },

This is failing on the update of catalog variable in RITM.

The need here is to allow the appropriate catalog variable to be shown on Glidedialogwindow for certain selection when Request was submitted(i have not yet gone to the part of querying based on selection bit) and the popup to accept the value and update the variable and workflow to be restarted from that point.

Appreciate your response.

1 ACCEPTED SOLUTION

I am using g_form.setValue('variable name', value) and this is working to set my solution.



Thanks for your time and help Kristen.


View solution in original post

11 REPLIES 11

kristenankeny
Tera Guru

If you check the history on the RITM, does it show that it updated and then saved the old value again? I ask because while your script include is doing the update, your UI Page Client Script is saving the form. I'm wondering if you're just writing it over with the displayed (old) value and if you should refresh the page instead. (I'm assuming that your alerts for the mailbox and ritm are coming back with the expected values?)


Hi Kristen,



Thanks for your response.



In history/Activity of RITM there is no changes at all. It appears like RITM table itself is not being touched at all.



I tried removing g_form.save() and ran again no changes .



And yes, alerts are showing right values


Two ideas:



- In your req.get('sysid') - remove the quotes, since you're referencing a variable



- If that doesn't resolve, try passing the mailbox sys_id as a string to see if that helps.


Did try that no luck