Hi guys,
Hope you are doing well. Right now Im building a custom app for freshservice and I need to avoid to update the ticket when the status is equal to 3. Im trying to use the intercept method but its not working. Can you please give me a hand? This is the code:
document.onreadystatechange = function() {
if (document.readyState === 'interactive') renderApp();
function renderApp() {
var onInit = app.initialized();
onInit
.then(function getClient(_client) {
window.client = _client;
client.events.on('app.activated', renderContactName, { intercept: true });
client.events.on("ticket.propertiesUpdated", eventCallBack, { intercept: true });
client.events.on("ticket.statusChanged", propertiesUpdatedCallback, {
intercept: true
});
})
.catch(handleErrors); // Corrected the function name here
}
};
var handleErrors = function(e) { // Simplified error handler function signature
console.error("Error occurred: ", e.message); // Log the error message to console
};
function renderContactName() {
console.log("APP INICIADA ");
let changeEvents = [
'ticket.priorityChanged',
'ticket.statusChanged',
'ticket.groupChanged',
'ticket.agentChanged',
'ticket.typeChanged', // Corrected typo here
'ticket.propertiesUpdated'
];
changeEvents.forEach(function(click) {
client.events.on(click, function(event) {
let eventName = event.type;
let { old: prevVal, new: newVal } = event.helper.getData();
console.log(eventName, prevVal, newVal);
if (eventName == "ticket.statusChanged" && newVal == "3") {
console.log("PRUEBA DETECTCION DE STATUS LISTS");
event.helper.fail(
"Timer(s) running. Stop the timer(s) before proceeding to close the ticket."
);
}
});
});
}
function eventCallBack(event) {
let eventName = event.type;
var data = event.helper.getData();
var statusA = data.status.value;
console.log(statusA, "DATA EVENTO TICKET PROPERTIES UPDATED");
if (statusA == '3') {
event.helper.fail(
"Timer(s) running. Stop the timer(s) before proceeding to close the ticket."
);
} else {
console.log("TICKET NO CERRADO");
}
}
function propertiesUpdatedCallback(event) {
// Ensure you define this function or ensure it is defined elsewhere in your code
console.log("Properties updated event received", event);
}
Thanks