[rt-users] Help with scrip for adding values to Custom Field

Kenneth Crocker kfcrocker at lbl.gov
Wed Aug 24 19:35:36 EDT 2011


To List,

I got it to work in terms of adding several good email addresses with this:
=====================================================
while ($UserObj = $GroupMembersObj->Next)
      {
       my $UserEmail = $UserObj->EmailAddress;
       my $cf_obj = RT::CustomField->new($RT::
SystemUser);
       $cf_obj->LoadByName(Name=>$cf_name);
       $RT::Logger->debug("Loaded\$cf_obj->Name = ". $cf_obj->Name() ."\n");
       $ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$UserEmail,
RecordTransaction=>0);
      }
====================================================
but I'm having trouble figuring out how to add a comma after each one in the
CF value list. That way the "To:" addresses will all be intact.

Anyone?

Kenn
LBNL

On Wed, Aug 24, 2011 at 2:25 PM, Kenneth Crocker <kfcrocker at lbl.gov> wrote:

> To list,
>
> I have a Custom Field I use as a "To" address for Others in a template; To:
> {$Ticket->FirstCustomFieldValue('QA Approver')}
>
> This CF is a "Select One Value" type.
>
> Now I have a situation that is similar, except that there will be more than
> one address to use. I figured I'd define the CF as "Enter Multiple values"
> and write a scrip to build those values. The email addresses would come from
> a group.
>
> This is what I have so far:
> ===================================================
> # set up initial values
>
> my $trans = $self->TransactionObj;
> my $ticket = $self->TicketObj;
> my $GroupName = "Test Group";
>
> # set up Group Objects
>
> my $GroupObj = RT::Group->new($RT::SystemUser);
> $GroupObj->LoadUserDefinedGroup($GroupName);
>
> # get out if wrong Group
>
> return 0 unless $GroupObj;
>
> # Walk thru Group and add an email address for that member
>
> my $cf_name = "Test-Team";
> my $GroupMembersObj = $GroupObj->UserMembersObj;
> my $UserObj;
>
> while ($UserObj = $GroupMembersObj->Next)
>       {
>        my $UserEmail = $UserObj->EmailAddress|(", ");
>        my $cf_obj = RT::CustomField->new($RT::SystemUser);
>        $cf_obj->LoadByName(Name=>$cf_name);
>        $RT::Logger->debug("Loaded\$cf_obj->Name = ". $cf_obj->Name()
> ."\n");
>        $ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$UserEmail,
> RecordTransaction=>0);
>       }
>
> return 1;
> =====================================================================
>
> I'm ending up with values for each member, but they are messed up. The
> first letter of the email address is bogus. I was hoping to get a string of
> values separated by that comma so I could just plug the CF into the
> template.
>
> I checked the log and no errors or warnings are showing up (Ruslan, I KNEW
> you'd ask that right off ;-).
>
> Any help would be GREATLY appreciated.
>
> Kenn
> LBNL
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20110824/a63feba2/attachment.htm>


More information about the rt-users mailing list