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

You seem to have some misconfiguration of business rules on your instance. Activate business rule debugger and check if something weird is happening.  

Changing of approval states  is done by out of the box rules.

I will try but the same thing happens on my own personal Dev instance which has not been changed other than to add the UI Action and UI Page I've added here.


Not sure why the fields are not getting updated out of the box. Just add the below business rule on sysapproval_approver table to update the source table and document id field for RITM's.



Condition : !(current.sysapproval.nil())


Script:


if(current.sysapproval.sys_class_name=='sc_req_item')


  {


  current.document_id=current.getValue('sysapproval');


  current.source_table='sc_req_item';


}


When: Before


Insert: True


The business rule needs to be defined on sysapproval_approver table. Can you try in any demo instance and let me know?


I can take a look into the instance if it doesn't work.


Apologies it does appear to work actually - I was being silly and expecting it to work on already created Requested Items, it woks on all new ones.