Problem creating scrip

I’m try to create a user defined scrip. What I want to do
is when a ticket is created, if it is a MemberOf (child of)
another ticket, and the partent ticket has a certain custom
field set, set the same value in the new ticket.

In other words, I am trying to propogate a custom field
value to the children of a ticket, at ticket creation time.

Here is my custome action preparation code so far:

my $Ticket = $self->TicketObj;
my $LinkObj = $Ticket->MemberOf;
my $Link = $LinkObj->Next;

Is is the 3rd line which triggers this error:

Jan 26 07:20:13 slah001 RT: RT::Scrip=HASH(0x9b52884): Couldn’t prepare User Defined (/opt/rt3/lib/RT/Scrip_Overlay.pm:346)

Can anyone spot the problem?

Thanks.

-Todd

The linkobj has not been instantiated yet.

A little ugly but this may get you started…

On create

Prep Code:
1

Commit code:
$found=0;
my $members = $self->TicketObj->MemberOf;
while (my $link = $members->Next) {
my $member= $link->BaseObj;
my $CustomFields = $member->TicketObj->QueueObj->CustomFields;
$CustomFields->LimitToQueue;
while (my $CustomField = $CustomFields->Next) {
#$RT::Logger->debug("Checking Field: " . $CustomField->Name);
if ($CustomField->Name=~// {
my $ParentFields = $self->TicketObj->QueueObj->CustomFields;
while (my $ParentField = $ParentFields->Next) {
if ($ParentField->Name=~// {
<code to set custom field (don’t know methods off hand and was
wondering if you could forward me that code when done) >
}
}
$RT::Logger->debug(“Found custom field " . $CustomField->Name . " in
parent and set in child, hopefully”);
$found=1
last; #dont need to go any farther
}
Last if ($found==1); #found memberof with pertinent custom field so stop
going through members.
}
}
return 1;

A.J.-----Original Message-----
From: rt-users-bounces@lists.bestpractical.com
[mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Todd Chapman
Sent: Monday, January 26, 2004 10:50 AM
To: rt-users@lists.bestpractical.com
Subject: [rt-users] Problem creating scrip.

I’m try to create a user defined scrip. What I want to do
is when a ticket is created, if it is a MemberOf (child of)
another ticket, and the partent ticket has a certain custom
field set, set the same value in the new ticket.

In other words, I am trying to propogate a custom field
value to the children of a ticket, at ticket creation time.

Here is my custome action preparation code so far:

my $Ticket = $self->TicketObj;
my $LinkObj = $Ticket->MemberOf;
my $Link = $LinkObj->Next;

Is is the 3rd line which triggers this error:

Jan 26 07:20:13 slah001 RT: RT::Scrip=HASH(0x9b52884): Couldn’t prepare User
Defined (/opt/rt3/lib/RT/Scrip_Overlay.pm:346)

Can anyone spot the problem?

Thanks.

-Todd

rt-users mailing list
rt-users@lists.bestpractical.com
http://lists.bestpractical.com/mailman/listinfo/rt-users

Have you read the FAQ? The RT FAQ Manager lives at http://fsck.com/rtfm

More info:

Here is what I have so far (thanks to AJ for helping):

my $Ticket = $self->TicketObj;
my $members = $Ticket->MemberOf;
my $link = $members->Next;
$RT::Logger->debug(“Calling BaseObj”);
my $parent = $link->BaseObj;
$RT::Logger->debug(“BaseObj called”);
my $value = $parent->FirstCustomFieldValue(“OAReqNum”);
$Ticket->AddCustomFieldValue(Field => 1, Value => $value);

I get the error “Can’t call method “BaseObj” on an undefined value”

I know this ticket has a parent. That is, unless the link
to the parent is created after the “On Create” scrip is run.

I have also found that the parent IS found if I change
the condition to “On Transaction”. So I guess the parent
link is created after the “On Create” scrip is run?

Any ideas?

Also, what is the difference between Stage: TransactionCreate
and Stage: TransactionBatch?

-Todd (Running RT 3.0.8)On Mon, Jan 26, 2004 at 10:50:03AM -0500, Todd Chapman wrote:

I’m try to create a user defined scrip. What I want to do
is when a ticket is created, if it is a MemberOf (child of)
another ticket, and the partent ticket has a certain custom
field set, set the same value in the new ticket.

In other words, I am trying to propogate a custom field
value to the children of a ticket, at ticket creation time.

Here is my custome action preparation code so far:

my $Ticket = $self->TicketObj;
my $LinkObj = $Ticket->MemberOf;
my $Link = $LinkObj->Next;

Is is the 3rd line which triggers this error:

Jan 26 07:20:13 slah001 RT: RT::Scrip=HASH(0x9b52884): Couldn’t prepare User Defined (/opt/rt3/lib/RT/Scrip_Overlay.pm:346)

Can anyone spot the problem?

Thanks.

-Todd


rt-users mailing list
rt-users@lists.bestpractical.com
The rt-users Archives

Have you read the FAQ? The RT FAQ Manager lives at http://fsck.com/rtfm