[rt-users] Using RT::Template with MIMEObj to create a new ticket using ->Create()

Ruslan Zakirov ruz at bestpractical.com
Sat Sep 14 16:19:22 EDT 2013


On Sat, Sep 14, 2013 at 11:58 PM, Landon Stewart <lstewart at iweb.com> wrote:

> On 14 September 2013 00:19, Ruslan Zakirov <ruz at bestpractical.com> wrote:
>
>> You should go other way around. After calling $template->Parse you call
>> $template->MIMEObj and get MIME::Entity representing result of the
>> template. You then can update this entity with attachments, more headers
>> and so on.
>>
>
> Hi Ruslan,
>
> Thanks for your reply.  I've just tried this but now I'm wondering where I
> get the TicketObj and TransactionObj arguments for $template->Parse.  If I
> use the Incident's TicketObj and TransactionObj it actually modifies the
> Incident's subject.
>
> I cannot put the $new_ticket->Create(…) before the $template->Parse
> because RT::Ticket->Create requires a MIMEObj produced by $template->Parse
> in $template->MIMEObj.  It's a chicken vs. egg issue here I think.  I must
> be missing something but I don't know what.  I also tried putting the "my
> $new_ticket = RT::Ticket->new($RT::SystemUser)" above the template but
> leave the Create below but I'm still left with no TransactionObj to use
> because it's generated by RT::Ticket->Create(…).
>


I don't understand your problem here. You have an incident and want to
create an investigation with a scrip using a template. Templates are used
here so you don't have to change code every time you to change a word or
add a new particular text for such investigations.

Here what you do:

1) scrip is executed when something happens with an Incident, so
$self->TicketObj is an Incident
2) You take Incident's props and use them to generate template name
3) You load template and Parse it, providing as much context as possible to
the template

Here is fun part - RT doesn't care what you pass into template. You can
probably even skip all arguments and if your template is capable to work
without arguments then it will work.

4) Template can have code embedded, so it can use provided context (in your
case Incident) to fill in dynamic details.
5) Template should not change anything, but format some result
6) After parsing you get MIMEObj based on existing Incident, IRs, watchers
of these tickets, CFs, transactions...
7) You complete this MIMEObj with additional data and these actions can be
controlled from templates, for example whether IRs's replies should be
attached to the Investigation or not can be controlled by 'RTIR-Attach-IRs:
yes' header (this is exactly what RT does in notification scrips)
8) Once MIMEObj is complete you create your investigation ticket

I don't see any chicken&egg problem here. Do you?


> I've pasted a new version of my code at http://pastebin.com/UvnUC221.
>  This version modifies the subject of the Incident ($self).
>
> --
> Landon Stewart :: lstewart at iweb.com
> Lead Specialist, Abuse and Security Management
> Spécialiste principal, gestion des abus et sécurité
> http://iweb.com :: +1 (888) 909-4932
>
>
>


-- 
Best regards, Ruslan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20130915/1c91b58e/attachment.htm>


More information about the rt-users mailing list