Hi Prem,
This issue is that the Web GUI Tool definition doesn't support nesting an sql block directly inside a script block like that. The Tool Editor forces you to choose a single type (Script, SQL, CGI, etc.), which is why it strips out the 'other' part when you save.
To get this to work, you should create a Script Tool (pure JavaScript) and use an AJAX request to execute the SQL update when your condition is met. You can do this by calling the ObjectServer REST API (OSLC) or the internal standard REST interface.
Here is an example of how to structure the Script Tool to do this:
// 1. Perform your Client-Side Logic
var x = 1; // Your logic here
var serial = row.Serial; // Get data from the selected row
if (x == 1) {
// Do nothing or handle the 'if' case
console.log("Condition met, no update needed.");
}
else {
// 2. Prepare the SQL Update payload
// Note: You typically use the OSLC/REST interface for this.
// This example uses a standard XMLHttpRequest to hit the ObjectServer REST API
var updateUrl = "/objectserver/restapi/alerts/status/" + serial;
var payload = {
"Location": username // Assuming 'username' is a variable you have defined
};
var xhr = new XMLHttpRequest();
xhr.open("PATCH", updateUrl, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 204) {
alert("Update successful");
} else {
alert("Error updating: " + xhr.statusText);
}
}
};
xhr.send(JSON.stringify(payload));
}
------------------------------
Sheerbit SEO
Sheerbit Technologies
Bothell WA
06174554551
------------------------------