0

Below is the JS code I've used to update the status field on order object when clicking on custom cancel button.

The issue i am facing here is when clicking on cancel button, confirm pop up shows up asking if I want to continue with cancellation by clicking ok or cancel the process by clicking cancel on pop up.

The status field is being updated even when i click on cancel on the pop up message.

Here I only want to perform a field update when user clicks on ok on the pop up.

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

try {
var url = parent.location.href;
var updateRecords = [];
var update_Order = new sforce.SObject("Order");
update_Order.Id ="{!Order.Id}";
update_Order.Status="Cancelled";
updateRecords.push(update_Order);

result = sforce.connection.update(updateRecords);
confirm('Are you sure you want to cancel?');
parent.location.href = url;
} catch (e) {
alert (e);
}

1 Answer 1

1

You need to use an if statement:

if(confirm('Are you sure you want to cancel?')) {
    result = sforce.connection.update(updateRecords);
    top.location.href = url;
}

The confirm method returns true when the user clicks OK or presses the Enter key, and false when the user clicks cancel, the X button, or Escape.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .