Is there a way to register interest in custom field changes dynamically

Comments

10 comments

  • Avatar
    James A. Rosen

    The app framework has neither support for adding/removing event listeners nor for declaring a listener on all ticket fields or all custom ticket fields. It is clear, though, that published apps (those available to all accounts) will need some solution for this. We're exploring some options and will update the framework changelog and errata page when we have more information.

  • Avatar
    Alan Byrne

    I need to be able to have access to this functionality for many of my apps (which presumably won't be published), so please consider making this functioanlity available generally to all apps.

    Can you give me an indication of when we are likely to get this kind of functionality.

  • Avatar
    James A. Rosen

    Alan: whenever we make it available to published apps we'll make it available to private ones as well. They use the same framework. I cannot give you any sort of precise estimate.

  • Avatar
    Grant Robertson

    I too am interested in dynamically attaching events to custom fields.

  • Avatar
    Alexis Tondelier

    Listening on custom fields "changed" events with field id being read from the app's settings is needed to avoid hard coded field ids in app.js. 

    So, hoping it will be implemented soon.

    The dynamic aspect may sound a little complicated facing the defineApp method's behaviour. An easier workaround would be to trigger a "ticket.custom_field.changed" event that would contain the field id as a parameter of the event.

     

    Maybe there is already such a mutualized event for custom fields changes ?

  • Avatar
    mejaguar

    events:

      '*.changed': function(event) {

        // event.propertyName = fieldname of the changed field

      }

    }

     

    You're welcome.

  • Avatar
    Alexis Tondelier

    Thanks for both answers.
    I should have tried the joker * !
    However as soon as an event specific to custom field events exists it will be a better practice.
    Thanks again.

  • Avatar
    Jake Holman

    Yep, what mejaguar put will work. We've not documented this just yet, but it's on the way. I've attached an app you can use to see how it works.

  • Avatar
    Caio Mathielo

    Well,  Custom ticket field change event actually exists now!

    It's very, very useful, but still I'm facing a huge problem. The situation: the app has the parameter brand_field_id, but the catch is that it is not required. Admin might choose whether to fill or not this field, thus taking advantage of it's functionality or not. 

    Expected behaviour: If admin fills brand_field_id, upon it's change a function will be triggered (and stuff will get done). But, if admin does not fill this field, nothing should happen.

    Following the documentation, I have added "ticket.custom_field_ticket.custom_field_{{brand_field_id}}.changed" as an app event. If the field is filled, the event works fine. Otherwise, javascript errors are thrown in the console and it could possibly cause harm to the app. 

    I have tried to check if the field is filled at app init, but it's useless as I cannot bind the event to the app once it has been loaded. This is what I've tried:

    if(!_.isEmpty(this.setting('brand_field_id'))){
    console.log('Brand change event added');
    this.events['ticket.custom_field_ticket.custom_field_{{brand_field_id}}.changed'] = 'brandChangedHandler';
    }

    I get to see "Brand change event added" in the console, but nothing happens once I change the custom field in the ticket screen.

    Is there a way out of this? It would be awesomely awesome if the framework automagically validated the {brand_field_id} before registering the event, but I wouldn't rely on that. If there was at least some way to append events on the go (say, on app.created function), I could do my checks before registering custom events.

  • Avatar
    Caio Mathielo

    Also, it would be nice to have a code snippet for this community forum editor! It's really hard to read code pieces posted here :(

Please sign in to leave a comment.

Powered by Zendesk