Add a comment to the ticket | Community
Skip to main content

Add a comment to the ticket

  • July 28, 2022
  • 2 replies
  • 0 views

Andrei15

Hi, 
Is it possible to add comments using ZAF client? Tried to use:

client.invoke('comment.appendText', 'some text') 
client.set('comment.text', 'some text')

They both just add a text to the texfield but do not publish it.

2 replies

Eric27
  • July 28, 2022
Hey Andrei,

You'll want to use the client.request method to make an api call to accomplish this. 
 
Hope this helps!

Julien18
  • August 4, 2022

You must use an API call. client.invoke or client.set both deal with the agent interface data - assignee, requester, fields values, etc but to update a ticket you must do like this :

client.get('ticket').then(function(response) {
  let ticket = response['ticket'];
  console.log(ticket['id']);
  client.request({
    url: '/api/v2/tickets/' + ticket['id'],
    contentType: "application/json",
    type: 'PUT',
    data: JSON.stringify({
      "ticket": {
        "comment": {
          "body": "Your comment goes here",
          "public": false
        }
      }
    })
  }).then(function(response) {
    console.log(response)
  })
});