diff --git a/lib/RT/REST2/Resource/Record/Writable.pm b/lib/RT/REST2/Resource/Record/Writable.pm index 3d81b25d5bc..e49b720a765 100644 --- a/lib/RT/REST2/Resource/Record/Writable.pm +++ b/lib/RT/REST2/Resource/Record/Writable.pm @@ -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' ) { @@ -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};