Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Approval widgets saving comments twice

Aanchal3
Kilo 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

Harsh Vardhan
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
Kilo 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
Kilo Contributor

Comments are not replicating.