How to stop previos "Custom ticket field change events"? | Community
Skip to main content

How to stop previos "Custom ticket field change events"?

  • August 12, 2022
  • 1 reply
  • 0 views

Василь

I will hang a listener on the field. When changing the macro, I need to cancel the previous listener on this field and hang a new one.
How to do it?
I try like this:
client.off(`ticket.custom_field_${f.id}.changed`);
but this is a "joke"...
As a result, I have worked out the old listener and the new one.

The macros use the same form, so the field I'm listening to doesn't get deleted.

1 reply

Va.Savitskyi
const client = ZAFClient.init();
client.invoke('hide');

client.on("app.registered", (data) => {
client.invoke("notify", `${client._context["location"]} app.activated`);
client.on('ticket.form.id.changed', function(e) {

if (e === 100_000_000) {
constparams = {
eventName:`ticket.custom_field_XXXXXXXXXX.changed`,
hendler:null
};
constfieldListener = fieldValidator.bind(params);
params.hendler = fieldListener
client.on(params.eventName, fieldListener);
}
});
});

function fieldValidator(e) {
// your code
console.log(this.eventName + ' validate value: ', e);

if (e === '333') {
client.off(this.eventName, this.hendler);
console.log('destroq validator for ' + this.eventName);
}
}