Recent searches


No recent searches

Corentin BERTEAU's Avatar

Corentin BERTEAU

Joined May 23, 2023

·

Last activity Nov 20, 2023

Following

0

Followers

0

Total activity

9

Vote

1

Subscriptions

3

ACTIVITY OVERVIEW

Latest activity by Corentin BERTEAU

Corentin BERTEAU commented,

Community comment Developer - Zendesk Apps Framework (ZAF)

Ok my bad.


   function requestCommentsTicket(client, id) {
      var settings = {
        url: '/api/v2/tickets/' + id + '/comments',
        type:'GET',
        dataType: 'json',
      };
    
      client.request(settings).then(
        function(data) {
          console.log('request result', data)
        },
        function(response) {
          console.log('request result', response)
        }
      );
    }

View comment · Edited Nov 20, 2023 · Corentin BERTEAU

0

Followers

1

Vote

0

Comments


Corentin BERTEAU created a post,

Post Developer - Zendesk Apps Framework (ZAF)

Hello, I am currently facing difficulties retrieving the latest public comment, and I have not found a solution in the documentation to identify whether a comment is public or not:

The client.get(ticket.comments) route retrieves all comments from ticket, but it does not retrieve the boolean parameter 'public' for comments.


Posted Nov 20, 2023 · Corentin BERTEAU

0

Followers

2

Votes

2

Comments


Corentin BERTEAU commented,

Community comment Developer - Zendesk Apps Framework (ZAF)

Hi,

Thanks for sharing this, my way to do this below but can't find a solution to update modal.html with some ticket info.

let client = ZAFClient.init();
let modalClient = null;
let parentClient = null;
let data;

function displayModal() {
  return new Promise((resolve) => {
    client.invoke('instances.create', {
      location: 'modal',
      url: 'assets/modal.html',
      size: {
        width: '450px',
        height: '200px'
      }
    }).then(function(modalContext) {
      // The modal is on screen now
        var modalClient = client.instance(modalContext['instances.create'][0].instanceGuid);
        // The modal has been closed
        modalClient.on('modal.close', function() {
          resolve('cancel');
        });
      client.on('modal.response', (response) => {
          resolve(response);
        });
    });    
  });
}


// Send the selected tags from the modal to the ticket sidebar
async function confirmChange() {
  console.debug("confirmChange called...");

  const context = await client.context();
  let instanceGuid = context.instanceGuid;
  modalClient = client.instance(instanceGuid);

  parentClient.trigger('modal.response', 'confirm');

  modalClient.invoke('destroy');
}

// Close the modal without sending changes to the ticket sidebar
async function cancelChange() {
  const context = await client.context();
  let instanceGuid = context.instanceGuid;
  modalClient = client.instance(instanceGuid);
  parentClient.trigger('modal.response', 'cancel');

  console.debug("cancelChange called...");
  modalClient.invoke('destroy');

}


// Ticket sidebar and modal button click listeners
window.addEventListener('DOMContentLoaded', function (event) {

  let displayModalButton = document.querySelector("#displayModal");
  let confirmButton = document.querySelector("#confirm");
let last_comment = document.querySelector("#last_comment");
  let cancelButton = document.querySelector("#cancel");
  let group_is_helpdesk = false;

  client.get('currentUser').then(function (currentUserData) {
    if (currentUserData && currentUserData.currentUser) {
      const currentUser = currentUserData.currentUser;
      const userGroups = currentUser.groups;
      userGroups.forEach(function (group) {
        if(group.id === 8995665084317)
        {
          let test = group.name;
          group_is_helpdesk = true;
        }
      });
    } else {
      console.error('Les données de l\'utilisateur actuel ne sont pas définies.');
    }
  }).catch(function (error) {
    console.error('Erreur lors de la récupération des données de l\'utilisateur actuel:', error);
  });

  client.on('ticket.save', async function () {
    if(group_is_helpdesk)
    {
      console.log(group_is_helpdesk);
      try {
        data = await client.get('ticket');  
        if (data && data.ticket) {
          console.log(data);
          const currentStatus = data.ticket.customStatus.name;
          if (currentStatus === 'Transfert vers SAV') {
            const userConfirmed = await displayModal();
            console.log(userConfirmed);
            if (userConfirmed === 'cancel') {
              console.log('L\'utilisateur a annulé l\'opération.');
              throw new Error('Annulation de la sauvegarde');
            }
            console.log('Le ticket peut être sauvegardé.');
            return "Transfert SAV en cours..."
          } else {
            throw new Error('Le statut n\'est pas "Transfert vers SAV".');
          }
        } else {
          throw new Error('Les données du ticket ne sont pas définies.');
        }
      } catch (error) {
        console.error(error.message);
        return Promise.reject(false);
      }
    } else {
      return Promise.reject(false);
    }
  });

  if (last_comment) {
    console.log('ici');
    console.log(data);
    last_comment.innerText = test;
  }

  if (confirmButton) {
    confirmButton.addEventListener("click", function () {
      console.log("Add Tags Button clicked.");
      confirmChange();
    });
  }

  if (cancelButton) {
    cancelButton.addEventListener("click", function () {
      console.log("Cancel Button clicked.");
      cancelChange();
    });
  }

});

// Framework events 

client.on('app.registered', function () {

  // Listen for the modal registration
  client.on('instance.registered', function (context) {
    if (context.location === 'modal') {
      let instanceGuid = context.instanceGuid;
      modalClient = client.instance(instanceGuid);

      // Trigger the event to send the parent instance GUID to the modal
      modalClient.trigger(
        'send_parent_client_guid_event',
        client._instanceGuid
      );
    }
  });

  // Receive the parent client instance 
  client.on('send_parent_client_guid_event', function (parentClientGuid) {
    console.debug('Receiving parent guid...', parentClientGuid);
    parentClient = client.instance(parentClientGuid);
  });
});

View comment · Posted Nov 16, 2023 · Corentin BERTEAU

0

Followers

0

Votes

0

Comments


Corentin BERTEAU commented,

Community comment Developer - Zendesk Apps Framework (ZAF)

Hi Daniel Wennerdahl

I'm trying to do the same thing, but from the moment my function is asynchronous, client.on('ticket.save', async function () {... return false;} doesn't work.

The only way I've found, and it's very ugly, is to call a nonexistent variable to block the sending by creating an error... If I find a solution or if I manage to make it work, I'll keep you informed.

It's possible anyway; the 'cancel submit ticket' application does exactly what we're trying to reproduce.

----
* update *
My bad, to cancel async function : return Promise.reject(false);

I will review my code and share my approach here asap. 

View comment · Edited Nov 16, 2023 · Corentin BERTEAU

0

Followers

0

Votes

0

Comments


Corentin BERTEAU commented,

Community comment Feedback - Ticketing system (Support)

Hi Ashwin Raju

+1 this feature is a must have. 

View comment · Posted May 23, 2023 · Corentin BERTEAU

0

Followers

1

Vote

0

Comments