[SOLVED] Add comment on new ticket

Hi there,

I am trying to automatically add a comment each time a ticket arrives. Scrip and template seemed to be the way to go but no matter what, no comment is added. Even using defaults template fails.
Capture d’écran 2021-08-17 à 12.07.07
I am looking for hints about where do I go from here.

Unless I’m misunderstanding what you are trying to do, you will probably need a custom action. This will create a comment transaction in response to the “On Create” condition. The template can probably be “Blank” as the custom action will contain the Perl required to create the new comment, including the text of the comment.

The only major “gotcha” I can see is that you want to use “On Create” so the ticket may not actually exist fully in the database yet (it is sort of half created inside an atomic SQL Transaction that isn’t committed until after the scrips have run). I’m not sure if that will mean that doing something like $self->TicketObj->Comment(Content => 'Hello'); in a custom action will fail or not.

Hi @GreenJimll
Many thanks for the care. I think you are right, ticket may not be in a “valid” state for comments to be added. I have tried every combination and none worked. So I may try to add a comment too early in the process.
Thanks a lot for your input.

OK, I’ve just tried it on one of our test/development RT instances and this seems to work:

  1. Create a new scrip on the queue, called whatever you want with the Condition set to On Create, the Action set to User Defined and the Template set to Blank.

  2. In the Custom action preparation code: panel just put:
    return 1;

  3. In the Custom action commit code: put:

    $self->TicketObj->Comment(Content => ‘Hello’);
    return 1;

  4. Save the resulting scrip.

Now if you create a new ticket you should see the initial transaction followed by a second one with the comment “Hello” in it.

Note that the comment is an RT transaction itself, so will fire off other scrips potentially.

Fantastic, that worked like a charm. Thanks a lot.