Facing Issue with Custom Field Value Update


#1

Hello Community/ Dev Team,

Please help us achieve the below objective.

There is one custom field by name, ‘Incident Condition’ in “Incidents” queue. This custom field has a drop down to select “src.ip+dst.ip”. We select this sometimes depending on the circumstance to create incident from incident report.

Now, we want ‘Incident Condition’ custom field to be replaced with actual source IP and destination IP instead of “src.ip+dst.ip”

Note: Custom fields ‘Source IP’ and ‘Destination IP’ exists in both ‘Incidents’ and ’ Incident Reports’ queue.

We are using RT 4.4

Below Scrip we wrote is not working for some reason. It seems FirstCustomFieldValue is not working. Please help.

Custom Condition:

my $txn = $self->TransactionObj;
my $queue = ‘Incidents’;
my $cf_name = ‘Incident Condition’;

RT::LoadConfig();
RT::Init();
my $tx = RT::Tickets->new($RT::SystemUser);
my $cf = RT::CustomField->new($RT::SystemUser);
my $q = RT::Queue->new($RT::SystemUser);
$q->Load($queue);
$cf->LoadByNameAndQueue(Queue => $q->Id, Name => $cf_name);

unless( $cf->id )
{
$cf->LoadByNameAndQueue( Name => $cf_name, Queue => ‘0’ );
}

unless( $cf->id )
{
die “Could not load custom field”;
}

my $cf_value = $txn->FirstCustomFieldValue($cf_name);

if((($txn->NewValue eq “open”) || ($txn->NewValue eq “new”))&&($cf_value eq “src.ip+dst.ip”))
{
return 1;
}
else
{
return 0;
}

Custom Action:

my $txn = $self->TransactionObj;
my $queue = ‘Incidents’;
my $cf_name_sip = ‘Source IP’;
my $cf_name_dip = ‘Destination IP’;

RT::LoadConfig();
RT::Init();
my $tx = RT::Tickets->new($RT::SystemUser);
my $cf = RT::CustomField->new($RT::SystemUser);
my $q = RT::Queue->new($RT::SystemUser);
$q->Load($queue);
$cf->LoadByNameAndQueue(Queue => $q->Id, Name => $cf_name);

unless( $cf->id )
{
$cf->LoadByNameAndQueue( Name => $cf_name, Queue => ‘0’ );
}

unless( $cf->id )
{
die “Could not load custom field”;
}

my $cf_value_sip = $txn->FirstCustomFieldValue($cf_name_sip);
my $cf_value_dip = $txn->FirstCustomFieldValue($cf_name_dip);
my $concat = $cf_value_sip.$cf_value_dip;
my $new_cf_value = $self->TicketObj->AddCustomFieldValue(Field => $cf->Id, Value => $concat);

P.S
We also tried this way $self->TicketObj->FirstCustomFieldValue($cf_name);


#2

Please close the case as we found a better way to achieve this objective.