We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Approval widgets saving comments twice

Aanchal3
Giga Contributor

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. 

13 REPLIES 13

hvrdhn88
Giga Patron

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.. 

 

Aanchal3
Giga Contributor

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();
}
})();

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();
}

Aanchal3
Giga Contributor

Comments are not replicating.