Approval widgets saving comments twice

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2019 02:45 AM
Hello,
I've updated the Approval Info widget and added a comment field, but when I add a comment and reject or accept a particular approval request, the comments are updated twice. I checked for UI Action, Client Script and others but cant find a solution.
Any suggestion would be appreciated.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2019 02:55 AM
have you written any server side script in your widget to update the comments ? if yes then can you please add some log there and validate it the issue is happening due to the widget script . give a try..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2019 03:17 AM
I added gr.comments = input.comment; in the existing server script.
(function() {
var gr = $sp.getRecord();
if (gr == null || !gr.isValid()) {
data.isValid = false;
return;
}
data.isValid = true;
data.isMine = gr.getValue("approver") == gs.getUserID();
if (!data.isMine && !gr.approver.nil())
data.approver = gr.approver.getDisplayValue();
if (input && input.op) {
gr.state = input.op;
gr.comments = input.comment; //Code to take input comment- different from OOB
gr.update();
}
var fields = $sp.getFields(gr, 'state,sys_created_on');
if (gr.sys_mod_count > 0)
fields.push($sp.getField(gr, 'sys_updated_on'));
data.fields = fields;
data.state = gr.state.toString();
data.sys_updated_on = gr.sys_updated_on.toString();
data.sys_id = gr.getUniqueValue();
data.table = gr.getTableName();
data.label = getRecordBeingApproved(gr).getLabel();
data.esignature = {
username: gs.getUserName(),
userSysId: gs.getUserID(),
e_sig_required: checkESig(gr.getValue("source_table"))
};
function checkESig(table) {
var esigRegistryGR = new GlideRecord("e_signature_registry");
if (!esigRegistryGR.isValid())
return false;
esigRegistryGR.addQuery("enabled", "true");
esigRegistryGR.addQuery("table_name", table);
esigRegistryGR.query();
return esigRegistryGR.hasNext();
}
function getRecordBeingApproved(gr) {
if (!gr.sysapproval.nil())
return gr.sysapproval.getRefRecord();
return gr.document_id.getRefRecord();
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2019 03:21 AM
try with this way.
Sample example : give a try.
change the script which you have added to update the comment.
if (input && input.op)
{
var counter = 0;
if(gr.state == "requested" && counter == 0)
{
gr.comments = input.comments;
gr.state = input.op;
counter++;
}
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2019 03:33 AM
Comments are not replicating.