On 5/18/11 Wed  May 18, 2011  5:06 PM, "CM Analyst" <cmanal...@yahoo.com>
scribbled:

> Hi,
> 
> In this code, the intent is to iterate through the tasks and modify the ID
> field. The Task record (entity) should not be modified if it's state equals
> "Completed". 
> 
> When I run this routine, there are two problems:
> 
> Problem 1) The "if" statement is not being evaluated. The record (even if it's
> in the "Completed" state is being modified.
> 
> Problem 2) Subsequent records (ie any record after the first one is not
> modfied). In other words, if I have multiple records, just the first one in
> the list gets modified. All others are skipped.
> 
> Can someone help me figure out where I am going wrong with this? Thanks.
> 
> <snip>
> 
> # Iterate through all tasks
> 
> foreach (@$tasks) {

You would be better to use an explicit variable here rather than the default
$_, especially since you are calling methods in the loop that might modify
the value of $_:

  foreach my $task ( @$tasks ) {

>     
> # Get a task entity for the current taskid (in $_)
> 
> my $taskEntity = $session->GetEntity ('almtask', $_);

We don't know what $session contains and what GetEntity does.

> 
> $taskEntity->GetFieldValue(state)->GetValue();

You have a bareword here (state). If this is supposed to be a string, then
you should quote it. state could be a function (or even a keyword in later
Perls):

  $taskEntity->GetFieldValue('state')->GetValue();

Do you have 'use strict;' in your program.

> 
> if ($taskEntity eq "Completed") {return;}

You probably don't want 'return' here. If you want to skip this task and go
to the next one in the loop, then you should use 'next'. 'return' will exit
from a function (although we don't know if this code is in a function since
you haven't shown us the whole code.):

  next if $taskEntity eq 'Completed';




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to