How do I display values of a reference list?

General question about the package, problems, solutions
gloria
Posts: 16
Joined: Mon Aug 17, 2009 6:40 pm

How do I display values of a reference list?

Postby gloria » Wed Oct 27, 2010 11:17 pm

Pavel:
Thanks for the great email packages and lots of useful answers on this forum.
Is it possible to display a number of values from a reference field in my message body?
For example, I have a reference list (Tasks) in the Request record. I would like to display the tasks (id, headline, and duedate) from the task list in the email notification. Is it possible?
When I displayed $tasks, it only display a list of the task id. How do I get the contents of the headline and duedate of the tasks displayed on the list as well?

Pavel
Posts: 281
Joined: Fri Dec 12, 2008 12:19 am

Re: How do I display values of a reference list?

Postby Pavel » Fri Oct 29, 2010 9:35 am

gloria wrote:Is it possible to display a number of values from a reference field in my message body?


Yes, it is possible, and there is more then one way to implement it.
First, you can use SQL to query children directly from the email notification rule, in a similar way as it was done for History in the examples of CCMA43 presentation.

Another way to implement it would be to create what we call "user defined function" that could be reused in multiple email notification rules.
Assume that your field name is "Tasks" and child record type is "Task". You can create udb_property record using "InsertTasks" as a name and the following code in the value of the record:

Code: Select all

my ( $qdef, $fnode, $resultset );
my $return_string = '';

my $values = $entity->GetFieldValue('Tasks')->GetValueAsList();

$qdef = $session->BuildQuery('Task');
$qdef->BuildField('ID');
$qdef->BuildField('DueDate');
$qdef->BuildField('Headline');
$fnode = $qdef->BuildFilterOperator($CQPerlExt::CQ_BOOL_OP_AND);
$fnode->BuildFilter( 'ID',  $CQPerlExt::CQ_COMP_OP_IN, $values);

$resultset = $session->BuildResultSet($qdef);
$resultset->Execute();

while( $resultset->MoveNext() == $CQPerlExt::CQ_SUCCESS ){
  my $id       = $resultset->GetColumnValue(1);
  my $duedate  = $resultset->GetColumnValue(2);
  my $headline = $resultset->GetColumnValue(3);
  $return_string .= "$id Duedate:$duedate Headline:$headline\n"
}

return $return_string;

Now, you can just use the function in your notification rule body field like

Code: Select all

InsertTasks()

It will insert children data there.

Regards,
Pavel

gloria
Posts: 16
Joined: Mon Aug 17, 2009 6:40 pm

Re: How do I display values of a reference list?

Postby gloria » Mon Nov 01, 2010 11:27 pm

Pavel:
Thanks so much.
Both choices are excellent.

Gloria.

edpmvl
Posts: 10
Joined: Mon Jun 20, 2011 3:17 pm

Re: How do I display values of a reference list?

Postby edpmvl » Mon Jun 20, 2011 6:41 pm

I want to display values from a Reference field in my Notification Body,as described in this post, but it is not displaying anything and i can´t figure out what i am doing wrong. My Reference List is Deliverables and i want to display item_id, delivery_type and IO_type. The child-record is called Delivery_Item. I changed the example code as follows:

my ( $qdef, $fnode, $resultset );
my $return_string = '';

my $values = $entity->GetFieldValue('Deliverables')->GetValueAsList();

$qdef = $session->BuildQuery('Delivery_Item');
$qdef->BuildField('Item_id');
$qdef->BuildField('Delivery_Type');
$qdef->BuildField('IO_Type');
$fnode = $qdef->BuildFilterOperator($CQPerlExt::CQ_BOOL_OP_AND);
$fnode->BuildFilter( 'Item_id', $CQPerlExt::CQ_COMP_OP_IN, $values);

$resultset = $session->BuildResultSet($qdef);
$resultset->Execute();

while( $resultset->MoveNext() == $CQPerlExt::CQ_SUCCESS ){
my $id = $resultset->GetColumnValue(1);
my $delivery_type = $resultset->GetColumnValue(2);
my $iotype = $resultset->GetColumnValue(3);
$return_string .= "$id Deliverable:$delivery_type IO Type:$iotype\n"
}

return $return_string;


There are 6 deliverables in the Reference List, for sure, and Item_id is one of the fields displayed, but no deliverable is displayed in the message body, so obviously CQ_SUCCES is False from the start.... I am overlooking something, but i cannot figure out what. Please help.... :(

Pavel
Posts: 281
Joined: Fri Dec 12, 2008 12:19 am

Re: How do I display values of a reference list?

Postby Pavel » Mon Jun 20, 2011 8:22 pm

edpmvl wrote:My Reference List is Deliverables and i want to display item_id, delivery_type and IO_type.

Is it stateless record type? What is the primary key?
I would recommend debugging your code as a stand-alone cqperl script first.

Regards,
Pavel


Return to “Email Notification Package Q&A”

Who is online

Users browsing this forum: No registered users and 0 guests

cron