- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 01:54 AM
Hi All,
My code is just updating the else condition if the value is matched. i want to give the error message as well.
var server = request.split(',');
for (var i = 0; i < server.length; i++)
{
var gr = new GlideRecord("u_server_details");
gr.addQuery("u_server_name.name", server[i].trim());
gr.query();
while (gr.next()) {
if (!gr.next()){
response.setStatus(400);
respObj.body = {
"message": "server details are not updated",
"detail": "faliure",
};
}
else{
response.setStatus(200);
gr.patch_date = requestTime;
gr.update();
respObj.body = {
"message": "Server Details are updated",
"detail": "Success",
};
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2023 08:29 AM
next question
do you want to show error message containing the name of servers not found in table?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 12:00 AM
you can do this
1) send status of 200 even if 1 server got updated
2) in that status message tell which servers got updated and which were not
var notFoundServers = [];
var foundServers = [];
for (var i = 0; i < server.length; i++)
{
var gr = new GlideRecord("u_server_details");
gr.addQuery("u_server_name.name", server[i].trim());
gr.setLimit(1);
gr.query();
if (!gr.next()){
notFoundServers.push(server[i].trim().toString());
}
else{
gr.next();
gr.patch_date = requestTime;
gr.update();
foundServers.push(server[i].trim().toString());
}
}
if(failedServers.length == 0){
response.setStatus(400);
respObj.body = {
"message": "All servers were not updated",
"detail": "faliure",
};
}
if(foundServers.length > 0 && failedServers.length > 0){
response.setStatus(200);
respObj.body = {
"servers_updated_message": "Server Details are updated for " + foundServers.toString(),
"servers failed ": "Server Details are not updated for" + failedServers.toString(),
"detail": "Success",
};
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2023 09:48 PM
yes.