Can't figure out how to pass the text from a dialog box into the sysapproval comments box?

evaoconnell
Giga Contributor

Hi there

In order to Reject Approval from a Context Menu,   I have created a ui action which then calls a ui page (with client script included) and displays a dialog box,   however when I click 'Ok' on the dialog box I'd like the text that was entered into the dialog box to copy into the comments box in the approval form.   Can't figure out how to do this?   Ideas welcome 🙂

1 ACCEPTED SOLUTION

UI action script: (Just add the line in bold)


function popupRejectApproval() {


  var gdw = new GlideDialogWindow('reject_request');


  gdw.setTitle('Reject this Request');


  gdw.setPreference("selectedRecord",rowSysId);


  gdw.render();


}



UI page client script:


function validateComments() {


  var selectedRecord = "${RP.getWindowProperties().get('selectedRecord')}";


  var dialcoms = gel("dialog_comments").value;


  var comments = trim(dialcoms);


  if (comments == "") {


  alert("Comments are mandatory for rejection");


  return false;


  }


  var getApproverRecord = new GlideRecord('sysapproval_approver');


  if(getApproverRecord.get(selectedRecord))


  {


  getApproverRecord.comments=comments;


  getApproverRecord.state='rejected';


  getApproverRecord.update();


  }


  GlideDialogWindow.get().destroy(); //Close the dialog window



}



Note: Change the querying part to a glideajax. Once the record is updated, redirect to the record you want else the screen will appear as static making you believe that the update has not happened.


View solution in original post

35 REPLIES 35

Not sure why do you need a pop up page for accepting the rejection. This is handled by the out of the box reject button. But anyway this would works. Replace the client script of the UI page.



function validateComments() {



  var dialcoms = gel("dialog_comments").value;


  comments = trim(dialcoms);


  if (comments == "") {


  alert("Comments are mandatory for rejection");


  return false;


  }


  g_form.setValue('comments',comments);


  g_form.setValue('state','rejected');


  g_form.save();


  GlideDialogWindow.get().destroy(); //Close the dialog window



}


Ishant Goyal1
Tera Contributor

You can do this using the processing script of ui page. Following is the sample code for a ui page.


HTML:


<?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:evaluate var="jvar_sys_id" expression="RP.getWindowProperties().get('sys_id_list')" />


  <input type="hidden" id="sysId" name="sysId" value="${jvar_sys_id}"/>


  <input type="hidden" id="cancelled" name="cancelled" value="false"/>


  <table width="100%">


        <tr>


      <td>


      <label for="reason">Reason</label>


      </td>


      <td width = "500">


      </td>


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


                    <textarea id="reason" name="reason" />


            </td>


        </tr>


  <tr id="dialog_buttons">


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


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


                    <g:dialog_buttons_ok_cancel ok="return validateData();" cancel="return cancel();"/>


              </td>


        </tr>


  </table>


  </g:ui_form>


</j:jelly>



Cleint Script:



function cancel() {


  var c = gel('cancelled');


  c.value = "true";


  GlideDialogWindow.get().destroy();


  return false;


}




function validateData() {


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



    //Make sure Impact is selected


  var res = gel("reason").value;


  if(res=='')


  {


  return false;


  }


}



Processing Script:


var gr = new GlideRecord('incident');


if(gr.get('sys_id',sysId))


{


  gr.work_notes = reason;


  gr.update();


}



Hope this will help


evaoconnell
Giga Contributor

Unfortunately this doesn't work.   The reason it's a dialog box is because it's a list context menu so not on the form, which may be why the g_form doesn't work.   I think I need to try something else, like maybe redirecting to the form when the reject list context menu is clicked.   Just need to figure out how to do that now


UI action script: (Just add the line in bold)


function popupRejectApproval() {


  var gdw = new GlideDialogWindow('reject_request');


  gdw.setTitle('Reject this Request');


  gdw.setPreference("selectedRecord",rowSysId);


  gdw.render();


}



UI page client script:


function validateComments() {


  var selectedRecord = "${RP.getWindowProperties().get('selectedRecord')}";


  var dialcoms = gel("dialog_comments").value;


  var comments = trim(dialcoms);


  if (comments == "") {


  alert("Comments are mandatory for rejection");


  return false;


  }


  var getApproverRecord = new GlideRecord('sysapproval_approver');


  if(getApproverRecord.get(selectedRecord))


  {


  getApproverRecord.comments=comments;


  getApproverRecord.state='rejected';


  getApproverRecord.update();


  }


  GlideDialogWindow.get().destroy(); //Close the dialog window



}



Note: Change the querying part to a glideajax. Once the record is updated, redirect to the record you want else the screen will appear as static making you believe that the update has not happened.


Fantastic that works.   Thank you so much.



It's conflicting with a Business Rule - so I'll just need to figure that one but it works....so I'm happy because it's been driving me crazy for weeks.



Thanks again