How to use dialog window

keerthi19
Tera Guru

I have requirement like..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 to redirect to 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.any one have any idea?

5 REPLIES 5

lakshminarayan4
ServiceNow Employee
ServiceNow Employee

hi ,


  You can create the "UI Action" for context menu on incident form . For Dialog box , you can use GlideDialogWindow . Please refer the documentation here for creating dialogs.



http://wiki.servicenow.com/index.php?title=GlideDialogWindow_API_Reference#gsc.tab=0


harishdasari
Tera Guru

Hi Keerthi,



To Accomlish your requirement



1). Create form context menu UI action.



var gdw = new GlideDialogWindow('YourUIpagename');


gdw.setTitle('Update Priority');


gdw.setSize(750,300);


gdw.setPreference('table', 'incident');


gdw.setPreference('title', 'A New Title');


gdw.render();



2).   Now Create UI page with the same name you have given in glidedialogwindow in UI action.



Now Create UI page and you the jelly scripting to update the Priority field.



Jelly Scripting



This tag is used to set the Value.



<j:set var="jvar_priority" value="${jvar_gr.getValue('priority')}"/>



Thanks


Hi Harish,



I tried to do this requirement



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 :



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




    //Make sure there are comments to submit


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


alert(+priority);



    }



    //If there are comments, close the dialog window and submit them


    GlideDialogWindow.get().destroy();




This Ui action is working , when i checked as form button, in list view its not updating the priority




where i should use this line, can you please help




<j:set var="jvar_priority" value="${jvar_gr.getValue('priority')}"/>


Hi Saranya,



Are you able to view alert in this method validateComments();



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