Checking for empty found set

Can anyone think why the following, in a calculation, would tell me that “global_activities_bu_callbacks is not defined” when there are no records in the found set?

It’s definitely a defined relationship.

I thought this was how to trap for an empty found set and avoid these errors. :-(

if( utils.hasRecords(global_activities_bu_callbacks))
{
    return global_activities_bu_callbacks.countRecords + ' callbacks required';
}
else
{
    return '0 callbacks required';
}

Cain,

I may be wrong but try this instead:

if(global_activities_bu_callbacks) 
{ 
    return global_activities_bu_callbacks.countRecords + ' callbacks required'; 
} 
else 
{ 
    return '0 callbacks required'; 
}

I’m not sure why I suggested that last mess!

This should work:

if(global_activities_bu_callbacks.getSize()) 
{ 
    return global_activities_bu_callbacks.countRecords + ' callbacks required'; 
} 
else 
{ 
    return '0 callbacks required'; 
}

Well, I used to do it that way, but I had problems consistently with that method…

Aw, hell, maybe I’ve got it backwards now. Anyone else?

Neither of my replies make sense now. I’m pretty sure the way you had it is correct and should work.

An alternative might be:

var activityCount = global_activities_bu_callbacks.getSize
if(activityCount >= 1) 
{ 
    return global_activities_bu_callbacks.countRecords + ' callbacks required'; 
} 
else 
{ 
    return '0 callbacks required'; 
}

Even better:

var activityCount = global_activities_bu_callbacks.getSize()
if(activityCount >= 1) 
{ 
    return global_activities_bu_callbacks.countRecords + ' callbacks required'; 
} 
else 
{ 
    return '0 callbacks required'; 
}

[/code]

Same error. :-(

Can anyone tell me how to trap for null values or empty sets? :?

I’ve been told…

if (table_to_table)
if (utils.hasRecords(table_to_table)
if (table_to_table.getSize > 0 )

None of this seems to work consistently. Perhaps if there were a checkbox somewhere that said “Do not evaluate if all referenced fields are empty”?

Cain,

I’ve just tested this successfully.

var numCalls = global_activities_bu_callbacks.getSize()
if (numCalls > 0)
{
	return numCalls + ' callbacks required';
}
else
{
	return '0 callbacks required';
}

Cain,

After thinking about this, I came up with the following:

return global_activities_bu_callbacks.getSize() + ' callbacks required';

I’ve tested this successfully.