How to disable the button after updating the record on the UI page?

sasipriya
Tera Contributor

Hi Team,

 

My requirement is that when I click on the reply button, I should get a mandatory comment box to provide refer-back comments.

 

I created a respond button to the risk form when the state is in review. Once the user submits the reason, reason comments should be updated in activity logs, and states should be changed to response; however, I'm having one issue: after adding comments and changing the state, the response button does not disappear until I refresh the page. I tried several other ways to refresh the page, but none of them worked. Could you please help me with this?

 

I have written the below code, please look into it.

 

UI ACTION Script:
 
function returnToDraft() {
    var dialog = new GlideModal('sn_risk_Return to response dialog');
    dialog.setTitle('Return To Response');
    dialog.render();
}
 
 
 
HTML SCRIPT :
 
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div class="dialog-form">
<p>Refer back comments</p>
  <label for="reason">Reason for edit:</label>
  <g:textarea id="reason" name="reason" style="width: 100%; height: 50px; " mandatory="true"></g:textarea>
  <button type="button" class="btn btn-primary" onclick="onSubmit()">Submit</button>
</div>
</j:jelly>
 
 
Client Script:
 
function onSubmit() {
    var reason = document.getElementById('reason').value;
document.getElementById("reason").required = true;
reason = reason.replace(/^\s+|\s+$/g, '');
    if (!reason) {
 
        document.getElementById("Please enter Reason").style.display='block';
        return false;
    }
 
    var ga = new GlideAjax('sn_risk.ReturnToResponseAJAX');
    ga.addParam('sys_id', g_form.getUniqueValue());
    ga.addParam('reason', reason);
    ga.getXMLAnswer(function(response) {
        if (response) {
            g_form.addInfoMessage('Reason provided: ' + reason);
            g_form.save();
//g_form.refresh();
//window.location.reload();
        }
    });
 
    GlideModalWindow.get().destroy();
    return true;
}
 
 
 
Script include script :
 
var ReturnToResponseAJAX = Class.create();
ReturnToResponse.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
process: function() {
        var sys_id = this.getParameter('sys_id');
        var reason = this.getParameter('reason');
 
        if (sys_id && reason) {
            var gr = new GlideRecord('sn_risk_risk');
            if (gr.get(sys_id)) {
                gr.state = 'respond'; 
                gr.comments = 'Returned to Response Reason is: ' + reason; 
                gr.update();
            }
        }
    }
});
 
Thanks &Regards,
Sasipriya
 
  

 

0 REPLIES 0