Re: [rt-users] warning message on set ReferTo

2014-12-25 Thread Alex Peters
The line in your first message:

$Ticket->AddLink(Type=>'RefersTo',Target=>$pticket_id,RecordTransactiosn=>0);

has a typo in "RecordTransaction", but I'm not sure that that parameter
actually applies to the AddLink method.  It can probably be removed
altogether.  In any case, I don't think that that is causing any problems.

Your scrip with the user-defined condition ("on create, if ticket subject
is not 'New App Request' and To: header does not include xx...@y.com")
doesn't seem relevant in this case, since your script doesn't appear to be
creating tickets.

I notice that you've only provided 70 lines of your script (79 lines are
missing).  I can't see any obvious problems with the code you've provided.
I suspect that the warnings are being caused by something earlier in the
script.

Out of curiosity, why do you run this code as a standalone script instead
of a scrip?  Your script operates specifically on Create transactions, so
wouldn't it be preferable to create all of the links at the time of ticket
creation?

On 25 December 2014 at 19:23, Payam Poursaied  wrote:

> Hi Alex
>
> That line copied exactly from the script.
>
>
>
> The whole idea of my script is searching for specific ticket based on
> customefiled and refer a newly created ticket to the first ticket which has
> the same customfiled value.
>
> First it fills some customfields based on body of the first transaction
> and tries then find the first ticket which is similar to that ticket (i.e.
> has the same value in one of its customfield) and creates a “Refer To” link
> to that ticket.
>
>
>
> Concept is very similar to
> http://requesttracker.wikia.com/wiki/AddRefersToOnEqualCustomField but
> instead of putting the code as a “Scrips” I run it as a standalone perl
> script.
>
>
>
>
>
> I have put my code and some of the errors below
>
>
>
> The only thing which might be relevant to this case is, I have one scrips
> with user defined condition.
>
> The condition code is in the below table:
>
> return 0 unless $self->TransactionObj->Type eq "Create";
>
> my $ChatArchiverTo='x\@y.com';
>
> my $scrip='scripname';
>
> my $TO="";
>
> if (defined($self->TransactionObj->Attachments->First->GetHeader("To"))){
>
> $TO = $self->TransactionObj->Attachments->First->GetHeader("To");
>
> }
>
> if($self->TicketObj->Subject =~ m/New App Request/){
>
>return 0;
>
> }
>
> if (($TO =~ /$ChatArchiverTo/i)){
>
>$RT::Logger->debug( "$scrip: $TO found in to");
>
>return 0;
>
> }
>
> else{
>
>$RT::Logger->debug( "$scrip: $TO was not found in to");
>
>return 1;
>
> }
>
>
>
>
>
> my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket
> search results
>
> $tickets->LimitQueue(VALUE =>'Appforall');
>
> $tickets->LimitSubject(VALUE=>'New App Request', OPERATOR=>'=');
>
> $tickets->LimitId(VALUE=>3234491,OPERATOR=>'>');
>
> $tickets->OrderByCols({FIELD=>'Id', ORDER =>'ASC'});
>
> $tickets->LimitCustomField(CUSTOMFIELD => $afa_req_type,
>
> OPERATOR=> "!=",
>
> VALUE   => $afa_req_type_type);
>
> while (my $Ticket = $tickets->Next) {
>
>  my $customer_id="";
>
>  my $app_name="";
>
>  my $txns = $Ticket->Transactions;
>
>  while (my $txn = $txns->Next ) {
>
> if ($txn->Type ne 'Create'){
>
> next;
>
> }
>
> my $attachments = RT::Attachments->new($txn->CurrentUser);
>
> $attachments->Limit( FIELD => 'TransactionID', VALUE => $txn->id );
>
> $attachments->ContentType (VALUE => 'text/plain');
>
> $attachments->OrderBy( FIELD => 'Id', ORDER => 'ASC' );
>
> while ( my $a = $attachments->Next ) {
>
>if($a->Content =~ /customer_id = (\d+).*app_name =
> ([^\n]+)/s){
>
>   $customer_id=$1;
>
>   $app_name=$2;
>
>   last;
>
>}
>
>}
>
>}
>
>
>
>   if ($customer_id  eq '' or $app_name eq ''){
>
>  print "ERROR: customer_id or app_name for ticket $Ticket->Id did
> not find\n";
>
>  next;
>
>   }
>
>   my $ptickets =  new RT::Tickets($RT::SystemUser);
>
>   $ptickets->LimitQueue(VALUE =>'Appforall');
>
>   $ptickets->LimitCustomField(CUSTOMFIELD => $afa_req_type,
>
> OPERATOR=> "=",
>
> VALUE   => $afa_req_type_type);
>
>   $ptickets->LimitCustomField(CUSTOMFIELD => $afa_appname,
>
> OPERATOR=> "=",
>
> VALUE   => "$app_name");
>
>   $ptickets->LimitId(VALUE=>$Ticket->Id,OPERATOR=>'<');
>
>   $ptickets->LimitId(VALUE=>3234491,OPERATOR=>'>');
>
>   $ptickets->OrderByCols({FIELD=>'Id', ORDER =>'ASC'});
>
>   my $pticket_id='';
>
>   if (my $PTicket=$ptickets->Next){
>
>  $pticket_id=$PTicket->Id;
>
>   }
>
>   print
> $Ticket->Id,"\t",$customer_id,"\t",$app_name,"PARENT-$pticket_id\n";
>
>
>
> 

Re: [rt-users] warning message on set ReferTo

2014-12-25 Thread Payam Poursaied
Hi Alex

That line copied exactly from the script.

 

The whole idea of my script is searching for specific ticket based on 
customefiled and refer a newly created ticket to the first ticket which has the 
same customfiled value. 

First it fills some customfields based on body of the first transaction and 
tries then find the first ticket which is similar to that ticket (i.e. has the 
same value in one of its customfield) and creates a “Refer To” link to that 
ticket.

 

Concept is very similar to 
http://requesttracker.wikia.com/wiki/AddRefersToOnEqualCustomField but instead 
of putting the code as a “Scrips” I run it as a standalone perl script.

 

 

I have put my code and some of the errors below

 

The only thing which might be relevant to this case is, I have one scrips with 
user defined condition. 

The condition code is in the below table:


return 0 unless $self->TransactionObj->Type eq "Create";

my $ChatArchiverTo='x\@y.com';

my $scrip='scripname';

my $TO="";

if (defined($self->TransactionObj->Attachments->First->GetHeader("To"))){

$TO = $self->TransactionObj->Attachments->First->GetHeader("To");

}

if($self->TicketObj->Subject =~ m/New App Request/){

   return 0;

}

if (($TO =~ /$ChatArchiverTo/i)){

   $RT::Logger->debug( "$scrip: $TO found in to");

   return 0;

}

else{

   $RT::Logger->debug( "$scrip: $TO was not found in to");

   return 1;

}

 

 

my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search 
results

$tickets->LimitQueue(VALUE =>'Appforall');

$tickets->LimitSubject(VALUE=>'New App Request', OPERATOR=>'=');

$tickets->LimitId(VALUE=>3234491,OPERATOR=>'>');

$tickets->OrderByCols({FIELD=>'Id', ORDER =>'ASC'});

$tickets->LimitCustomField(CUSTOMFIELD => $afa_req_type,

OPERATOR=> "!=",

VALUE   => $afa_req_type_type);

while (my $Ticket = $tickets->Next) {

 my $customer_id="";

 my $app_name="";

 my $txns = $Ticket->Transactions;

 while (my $txn = $txns->Next ) {

if ($txn->Type ne 'Create'){

next;

}

my $attachments = RT::Attachments->new($txn->CurrentUser);

$attachments->Limit( FIELD => 'TransactionID', VALUE => $txn->id );

$attachments->ContentType (VALUE => 'text/plain');

$attachments->OrderBy( FIELD => 'Id', ORDER => 'ASC' );

while ( my $a = $attachments->Next ) {

   if($a->Content =~ /customer_id = (\d+).*app_name = ([^\n]+)/s){

  $customer_id=$1;

  $app_name=$2;

  last;

   }

   }

   }

 

  if ($customer_id  eq '' or $app_name eq ''){

 print "ERROR: customer_id or app_name for ticket $Ticket->Id did not 
find\n";

 next;

  }

  my $ptickets =  new RT::Tickets($RT::SystemUser);

  $ptickets->LimitQueue(VALUE =>'Appforall');

  $ptickets->LimitCustomField(CUSTOMFIELD => $afa_req_type,

OPERATOR=> "=",

VALUE   => $afa_req_type_type);

  $ptickets->LimitCustomField(CUSTOMFIELD => $afa_appname,

OPERATOR=> "=",

VALUE   => "$app_name");

  $ptickets->LimitId(VALUE=>$Ticket->Id,OPERATOR=>'<');

  $ptickets->LimitId(VALUE=>3234491,OPERATOR=>'>');

  $ptickets->OrderByCols({FIELD=>'Id', ORDER =>'ASC'});

  my $pticket_id='';

  if (my $PTicket=$ptickets->Next){

 $pticket_id=$PTicket->Id;

  }

  print 
$Ticket->Id,"\t",$customer_id,"\t",$app_name,"PARENT-$pticket_id\n";

 

  if (defined($ARGV[0]) and  $ARGV[0] eq 'set'){

  $Ticket->AddCustomFieldValue(Field=>$afa_channel,

Value=>$afa_chat,

 RecordTransaction=>0);

  $Ticket->AddCustomFieldValue(Field=>$afa_req_type,

Value=>$afa_req_type_type,

 RecordTransaction=>0);

  $Ticket->AddCustomFieldValue(Field=>$afa_customerid,

Value=>$customer_id,

 RecordTransaction=>0);

  $Ticket->AddCustomFieldValue(Field=>$afa_appname,

Value=>$app_name,

 RecordTransaction=>0);

  if ($pticket_id ne ''){

 
$Ticket->AddLink(Type=>'RefersTo',Target=>$pticket_id,RecordTransactiosn=>0);

  }

  }

  } # Ticket loop

$RT::Handle->Disconnect();

exit;

 

[21743] [Mon Dec 22 08:21:54 2014] [warning]: RT::Handle=HASH(0x802572660) 
couldn't execute the query 'SELECT COUNT(DISTINCT main.id) FROM Scrips main 
JOIN ObjectScrips ObjectScrips_1  ON ( ObjectScrips_1.Scrip = main.id ) JOIN 
ScripConditions ScripConditions_2  ON ( ScripConditions_2.id = 
main.ScripCondition )  WHERE (ObjectScrips_1.ObjectId = '120' OR 
ObjectScrips_1.ObjectId = '0') AND (ObjectScrips_