Skip to content

Commit

Permalink
Issue #2987: Store additional set index df value for sets.
Browse files Browse the repository at this point in the history
Use it to determine how many script values we need to store in multivalue sets.
  • Loading branch information
stefanhaerter committed Feb 26, 2024
1 parent 3c198ad commit fd4ab00
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Kernel/System/DynamicField/Driver/Set.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use Kernel::System::VariableCheck qw(:all);

our @ObjectDependencies = (
'Kernel::System::DynamicField',
'Kernel::System::DynamicFieldValue',
'Kernel::System::DynamicField::Backend',
'Kernel::Output::HTML::DynamicField::Mask',
'Kernel::System::Log',
Expand Down Expand Up @@ -167,6 +168,19 @@ sub ValueSet {
}
}

# set index_set to check how many set values we have
my $Success = $Kernel::OM->Get('Kernel::System::DynamicFieldValue')->ValueSet(
FieldID => $Param{DynamicFieldConfig}->{ID},
ObjectID => $Param{ObjectID},
Value => [
{
ValueText => 'set_index',
IndexSet => scalar @SetValue,
},
],
UserID => $Param{UserID},
);

return 1;
}

Expand Down
30 changes: 30 additions & 0 deletions Kernel/System/Ticket/Event/EvaluateScriptFields.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ our @ObjectDependencies = (
'Kernel::System::Cache',
'Kernel::System::Log',
'Kernel::System::DynamicField',
'Kernel::System::DynamicFieldValue',
'Kernel::System::DynamicField::Backend',
'Kernel::System::DynamicField::Driver::BaseScript',
'Kernel::System::Ticket',
Expand Down Expand Up @@ -65,23 +66,52 @@ sub Run {

my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');
my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
my $DynamicFieldValueObject = $Kernel::OM->Get('Kernel::System::DynamicFieldValue');

my %Ticket = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet(
TicketID => $Param{Data}{TicketID},
DynamicFields => 1,
UserID => 1,
);

FIELD:
for my $FieldID ( $Events->{ $Param{Event} }->@* ) {

my $DynamicField = $DynamicFieldObject->DynamicFieldGet(
ID => $FieldID,
);

# if we store set values, get set index to determine how many values we need to store
my $SetIndex;
if ( $DynamicField->{Config}{PartOfSet} ) {
my $SetConfig = $DynamicFieldObject->DynamicFieldGet(
ID => $DynamicField->{Config}{PartOfSet},
);

if ( $SetConfig->{Config}{MultiValue} ) {
my $SetIndexValue = $DynamicFieldValueObject->ValueGet(
FieldID => $SetConfig->{ID},
ObjectID => $Param{Data}{TicketID},
);

next FIELD unless $SetIndexValue->@*;

$SetIndex = $SetIndexValue->[0]{IndexSet};
}
else {
$SetIndex = 0;
}
}

my $Result = $DynamicFieldBackendObject->Evaluate(
DynamicFieldConfig => $DynamicField,
Object => \%Ticket,
);

if ( defined $SetIndex ) {
$Result = [ map {$Result} ( 0 .. $SetIndex - 1 ) ];
}

$DynamicFieldBackendObject->ValueSet(
DynamicFieldConfig => $DynamicField,
ObjectID => $Param{Data}{TicketID},
Expand Down

0 comments on commit fd4ab00

Please sign in to comment.