Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/RT/REST2/Resource/Record/Writable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,25 @@ sub create_record {

# Lookup CustomFields by name.
if ($cfs) {
my $context_object;
my $context_id = 0;
if ( $record->isa('RT::Ticket') ) {
$context_object = RT::Queue->new( RT->SystemUser );
$context_object->Load($args{Queue});
} elsif ( $record->isa('RT::Asset') ) {
$context_object = RT::Catalog->new( RT->SystemUser );
$context_object->Load($args{Catalog});
} elsif ( $record->isa('RT::Article') ) {
$context_object = RT::Class->new( RT->SystemUser );
$context_object->Load($args{Class});
}
if ( $context_object ) {
if ( $context_object->id ) {
$context_id = $context_object->id;
} else {
RT->Logger->warning("Unable to load context object");
}
}
foreach my $id (keys(%$cfs)) {
my $value = delete $cfs->{$id};
if ( ref($value) eq 'HASH' ) {
Expand Down Expand Up @@ -330,8 +349,11 @@ sub create_record {
$cfs->{$id} = $value;

if ($id !~ /^\d+$/) {
my $cf = $record->LoadCustomFieldByIdentifier($id);

my $cf = RT::CustomField->new( $record->CurrentUser );
my ($val, $msg) = $cf->LoadByName( Name => $id,
LookupType => $record->CustomFieldLookupType,
ObjectId => $context_id,
IncludeGlobal => 1 );
if ($cf->Id) {
$cfs->{$cf->Id} = $cfs->{$id};
delete $cfs->{$id};
Expand Down