Can you let us know please what you mean by “stopped working”? Does a specific error occur by executing the provided JavaScript code by a Run Script Workflow plugin, for example?
Tip: I would advice to declare the variable totalDocuments outside the if-statement instead, as shown in the below modified version of the shared script.
// ...
var totalPages = 0;
var totalDocuments = 0;
// ...
if (xhr.status === 200) {
// ...
totalDocuments = job.length;
// ...
}
// ...
Looks like the localhost loopback is not enabled on your new server. You can test that theory by changing localhost to 127.0.0.1.
If that works, then you can simply use that IP address, but if you absolutely want to use the localhost name, you can follow the procedure outlined in this Microsoft Learn article.