[Rt-devel] duplicating a scrip in code

Todd Chapman todd at chaka.net
Thu Jan 5 10:32:31 EST 2006


On Thu, Jan 05, 2006 at 05:15:16PM +1100, Jens Porup wrote:
> On Thu, Jan 05, 2006 at 12:28:19AM -0500, Todd Chapman wrote:
> > On Thu, Jan 05, 2006 at 04:17:34PM +1100, Jens Porup wrote:
> > > 
> > > Here's a poser for you.
> > > 
> > > I have a Scrip/Template combo that creates a ticket.
> > > 
> > > Now I want to duplicate that code in custom code.
> > > 
> > > I could try to duplicate that as $Ticket->Create() code,
> > > but as soon as I start looking for the Parent and DependsOn
> > > params (which don't seem to be there!) I hit a wall.
> > > 
> > > Then I think why can't I just load the already existing
> > > Scrip and Template, and execute them? This would prevent
> > > any discrepancy creeping in between the coded action and
> > > the scrip.
> > > 
> > > But.... how do I do this? I see the $Scrip->Apply() method,
> > > but there's no $Scrip->Load() method.
> > > 
> > > So how do I bring up the scrip I want, so that I can then
> > > execute it?
> > > 
> > > Suggestions or other ways of looking at this most appreciated.
> > > 
> > > Thanks,
> > > 
> > > Jens
> > 
> > Normally a transaction triggers a scrip, so I would look at
> > the Transaction code (probably the Create method) and see
> > how it loads and runs a scrip. This may not work though
> > because a scrip may expect to run in the context of a
> > transaction.
> 
> Hmmmm.....
> 
> The perldoc for Transaction_Overlay says:
> 
> Create
> 
>        Create a new transaction.
> 
>        This routine should _never_ be called anything other Than
>        RT::Ticket. It should not be called from client code. Ever. Not
>        ever. If you do this, we will hunt you down. and break your
>        kneecaps. Then the unpleasant stuff will start.
> 
> ...I'm not sure what this means, but I don't think I want to go there.
> 
> > It would be better to write the code to do what you want
> > and then have the scrip call that code. That avoids the
> > duplication problem.
> 
> Maybe I should be a bit clearer. 
> 
> My scrip creates a ticket using a template. That's all.
> 
> The reason the idea of executing the scrip from code occurred
> to me is that I can't figure out how to pass the template parameters
> to my $Ticket-Create() call, like Parents, and DependsOn, things
> like that.
> 
> Do you see what I mean? The entire "action" of the scrip is already
> contained in the scrip itself and the template associated with it.
> It makes sense for it to stay there. 
> 
> I just want to execute it from code.
> 
> But how?
> 
> Thanks,
> 
> Jens

I understand want you want but it's just not the right way
and will probably not work. Adding links during ticket creation
is not documented, but it's not hard. Just pass an option
with the link type and the id of the ticket you are linking
to. For example:

   $ticket->Create(
        Queue => 5,
      Subject => 'test',
       Parent => 234,
    DependsOn => [ 189, 190 ]
              .
              .
              .


As you see you can link to multiple ticket by passing
and array ref instead of a single ticket id.

-Todd


More information about the Rt-devel mailing list