Custom field data not saving after code is run

3 댓글

  • Amie

    Hey Jesse Spalding,

    In general, when you make an update to a ticket field, you do then need to submit the ticket so it saves the changes you've made. Submitting the ticket normally requires the agent to also select a status at the same time. 

    Perhaps you will need to include a submit function into your code here where you are adding the status into the update you're making. 

    https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#update-ticket

    I not a developer by nature but I hope this helps. :)

     

     

    1
  • Hanna Jordan

    Hi, I think the problem is that you are using the ticket.save() method inside the ticketFields:changed event handler. This will cause an infinite loop of saving and changing the ticket fields, which may prevent the custom field data from being saved properly. A possible solution is to use a flag variable to check if the custom field data has been updated before saving the ticket. For example:

    Hope this helps,
    Hanna from CodeIT

    var updated = false; // flag variable

    client.on('ticketFields:changed', function(e) {
      if (e.fieldId === 'status') {
        var status = e.value;
        if (status === 'solved') {
          client.get('ticket.customField:custom_field_360000000000').then(function(data) {
            var customField = data['ticket.customField:custom_field_360000000000'];
            if (customField !== 'Yes') {
              client.set('ticket.customField:custom_field_360000000000', 'Yes');
              updated = true; // set flag to true
            }
          });
        }
      }
    });

    client.on('ticket.save', function() {
      if (updated) { // check flag before saving
        return true;
      } else {
        return false;
      }
    });

    1
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Hi Jesse Spalding,

    In your payload ticketCustomFieldData, you should change fields to custom_fields. That should the update issue.

    However, the app seems to perform the update every time it is loaded since it will always register with has_run as false. So, every time the ticket is opened, the fields will be updated.

    I believe your use case can benefit more from a ZIS app rather than a ZAF one.

    1

댓글을 남기려면 로그인하세요.

Zendesk 제공