-> In suiteLet add the custom button:
let form = serverWidget.createForm({
title: “Custom Suitelet Form”
});
form.addButton({
id: ‘custpage_delete_button’,
label: ‘Delete’,
functionName: `deleteButton()`
});
//Sending the response
if(scriptContext.request.method === ‘DELETE’){
record.delete({
type: record.Type.TASK,
id: internalId
});
scriptContext.response.write({
output: JSON.stringify({
success: true,
data: {
“id”: internalId
}
}),
contentType: ‘application/json’
})
}catch(error){
scriptContext.response.write({
output: JSON.stringify({
success: false,
message: error.message
}),
contentType: ‘application/json’
})
}
}
-> In Client script sending https.delete.promise request
function deleteButton() {
try {
let options = {
title: ‘Delete Confirmation’,
message: ‘Are you sure you want to delete this record? This action cannot be undone.’
};
dialog.confirm(options)
.then(function (result) {
if (result) {
https.delete.promise({
url: window.location.href
}).then(function (response) {
let responseBody = JSON.parse(response.body);
if (responseBody.success) {
message.create({
type: message.Type.CONFIRMATION,
title: “Record Deleted”,
message: “Record Deleted Successfully,
duration: 5000
}).show();
} else {
message.create({
type: message.Type.ERROR,
title: “Record Deleted Failed”,
message: message.error
duration: 5000
}).show();
}
}).catch(function (error) {
console.log(“HTTP Request Error”, error);
});
}else{
console.log(“Deletion button Error”);
}
}).catch(function (){
console.log(“Error @ Delete Button”);
})
} catch (error) {
console.log(“error @ deleteButton”, error.message);
}
}
return {
deleteButton: deleteButton
};