Updating a field by getting input from dialog window.

saranyadevic
Kilo Contributor

Hi all,

I have requirement .we have incident record when we right click that record it has to show custom UI action called update priority.if I click that it has open a dialog window and it should have field called priority with options..if select any priority and tries to submit .once submitted that priority should needs to update in original record.

for that i have created

UI action :

function updatePriority() {

var sysId = typeof rowSysId == 'undefined' ? gel('sys_uniqueValue').value : rowSysId;

var input_priority = gel('priority');

var gDialog = new GlideDialogWindow("inc_update_priority");

gDialog.setTitle("Update Priority");

gDialog.setPreference('sysparm_sysID', sysId);

gDialog.setPreference('sysparm_table', "incident");

gDialog.setPreference('input_priority',input_priority);

gDialog.render();

}

Ui page : inc_update_priority

Html :

<g:ui_form>

<input type="hidden" id="incidentSysID" name="incidentSysID" value="${sysparm_sysID}"/>

    <!-- Get the values from dialog preferences -->

      <g:evaluate var="jvar_comments_text"

      expression="RP.getWindowProperties().get('comments_text')" />

    <!-- Set up form fields and labels -->

    <table width="100%">

   

        <tr>

            <td>

                <!-- Comments text field (Contains comments from originating record as a default) -->

              <select name="priority" id="priority" mandatory="true" value="${jvar_comments_text}" >

  <option value="1">1 - Critical</option>

  <option value="2">2 - High</option>

  <option value="3">3 - Moderate</option>

  <option value="4">4 - Low</option>

</select>

            </td>

        </tr>

        <tr>

            <td colspan="2">

            </td>

        </tr>

        <tr id="dialog_buttons">

              <td colspan="2" align="right">

                    <!-- Add OK/Cancel buttons. Clicking OK calls the validateComments script -->

                    <g:dialog_buttons_ok_cancel ok="return validateComments()" ok_type="button" cancel_type="button" />

              </td>

          </tr>

  </table>

</g:ui_form>

Client Script :

function validateComments() {

    //This script is called when the user clicks "OK" in the dialog window

    var priority = gel("priority").value;

alert(+priority);

    }

    GlideDialogWindow.get().destroy();

This Ui action is updating the priority , when i checked as form button, in list view its not updating the priority, can anyone please help

1 ACCEPTED SOLUTION

Hi Saranya,



yes GlideRecord works in client script of ui page.


Also use window.location.reload(); instead of location.reload()



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Saranya,



For form button you should use g_form.getUniqueValue() to get the record sysId and for list button you should use rowSysId to get the row sysId where button is clicked.


Also why are use using following line of code in your ui action since you told user will select drop down from ui page



var input_priority = gel('priority'); // is this required?



Also can you alert sysId i.e. sysId when you click on list button?


This will tell you whether you are getting the sysId or not.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Saranya,



Also you will need to update the incident record in this method and reload the form to view the update.function validateComments(){



var incRec = new GlideRecord('incident');


incRec.addQuery('sys_id', gel('incidentSysID').value);


incRec.query();


if(incRec.next()){


incRec.priority = gel('priority').value;


incRec.update();


}


location.reload();


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

thanks Ankur, i will try this


Hi Saranya,



Yes please let us know whether any issue or it is working so that you can close this question.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader