The Now Platform® Washington DC release is live. Watch now!
‎04-04-2018 12:52 AM
Hi All,
We had a requirement of adding comments for the approval being rejected, on the Approval widget on service portal.
I came up with adding a textbox, on the widget for every approval on the form. This makes the reject button disable, until there is some context added in the textbox and you need to add some text to reject the comments.
I am passing the comments then with the same function that is passing the state of the approval, reject or approved.
Everything is working fine, except, the comments are being saved around 6 times minimum for a single reject or approve.
I am not able to figure out why this is happening, as the state is being changed only once, which would make sense as the code which looks for the approval with requested type has already been changed by the server script. But the comments keep been added. But I don't understand why the code still keeps running and calling the script.
I have attached the widget on which I have made changes. Can I request some assistance on this please, any suggestion would be appreciated?
Regards,
Vikrant Sharma
‎04-04-2018 01:48 AM
Hi Vikrant,
Some areas you might want to look into are:
1. UI Action
2. ACL
3. Any workflow activity running on the background
Also for additional comments, can you try the below and let me know the findings.
1. Approve or reject a request
2. Give the comments.
3. Hover and click outside the comment section (simply click on an area outside the comment text box)
4. Save the record.
You could refer to these community articles
duplicate entries in activity
Work Notes duplicate entry in Activty Log
UI Action updating twice
Kind Regards,
Satyaki Bose
Technical Support Engineer - UX
ServiceNow | Work at Lightspeed
‎04-04-2018 04:58 AM
Thanks for your reply satyaki, but I guess the issue is with the widget executing the loop below, on server script:
if (input && input.op) {
var app = new GlideRecord("sysapproval_approver");
if (app.get(input.target)) {
app.comments = input.comments;//Testing
app.state = input.op;
gs.log("VRS: How many times the loops executes? values of input: "+input + " and input.op: "+ input.op);
app.update();
}
}
When I change the script to below:
if (input && input.op) {
var app = new GlideRecord("sysapproval_approver");
if (app.get(input.target)) {
if(app.state == "requested" ){
app.comments = input.comments;//Testing
app.state = input.op;
}
gs.log("VRS: How many times the loops executes? values of input: "+input + " and input.op: "+ input.op);
app.update();
}
}
It now update the comment only once, but the gs.log statement still executes multiple times.
I am just try to understand why the script is being executed at least six time, while the comments are only being edited once.
So, I am trying to understand why this happens.
Thanks for your suggestions.
‎10-05-2018 03:58 AM
I experienced the same and do not understand why the comment is added two times. Not the best solution but I added a counter in the script. The log statement is now appearing once.
if (input && input.op)
{
var counter = 0;
if(gr.state == "requested" && counter == 0)
{
gr.comments = input.comments;
gr.state = input.op;
counter++;
}
gr.update();
}
‎05-09-2019 06:20 AM
Hi,
we had the exact same issue.
Our solution - modify the following line in the client controller:
spUtil.recordWatch($scope, "sysapproval_approver", "state=requested^approverIN" + $scope.data.myApprovals.toString());
to
spUtil.recordWatch($scope, "sysapproval_approver", "state=requested^approverIN" + $scope.data.myApprovals.toString(), function(response) {});
Regards,
Heiko