Topic
  • 5 replies
  • Latest Post - ‏2013-10-23T07:07:57Z by CQAdmin
Matthew.Mallard
Matthew.Mallard
2 Posts

Pinned topic Using AdReferenceListField as a AdReferenceField

‏2013-10-21T15:27:38Z |

When attempting to go more than two layers deep with the following code I receive a "Using AdReferenceListField as a AdReferenceField" error.

 

Code Example:

my $fieldValue2 = $entity->GetFieldStringValue("Submitter.groups.name");

 

Is there a workaround for this problem?

 

  • pdubovitsky
    pdubovitsky
    376 Posts

    Re: Using AdReferenceListField as a AdReferenceField

    ‏2013-10-21T17:39:51Z  

    In your example, group name is a primary key for the "groups" record type, so you can use

    $fieldValue2 = $entity->GetFieldValue("Submitter.groups")->GetValueAsList();
    for my $group_name (@$fieldValue2) {
      <do something>
    }

    In other cases, when you need to access non-primary key value, running a query might be more efficient way to do it.

    Pavel

  • Matthew.Mallard
    Matthew.Mallard
    2 Posts

    Re: Using AdReferenceListField as a AdReferenceField

    ‏2013-10-21T17:52:10Z  

    In your example, group name is a primary key for the "groups" record type, so you can use

    $fieldValue2 = $entity->GetFieldValue("Submitter.groups")->GetValueAsList();
    for my $group_name (@$fieldValue2) {
      <do something>
    }

    In other cases, when you need to access non-primary key value, running a query might be more efficient way to do it.

    Pavel

    Thank you for the reply. "Submitter.group.name" is just used as an example. The goal is to pull an e-mail from a field three layers deep. Then take this e-mail and send a message to it. This is all based off of a record being changed within clearquest.

     

    here's the some rough pseudo code:

    if the record changes to said state

    get the e-mail string

    my $fieldValue2 = $entity->GetFieldStringValue("Associated_Actions.Assignee.email")

    send e-mail to ("fieldValue2");

     

    ----

     

     

    yes a query would be much easier, but the e-mail field is needed for a notification action upon the change state of a record.

  • pdubovitsky
    pdubovitsky
    376 Posts

    Re: Using AdReferenceListField as a AdReferenceField

    ‏2013-10-21T18:05:09Z  

    Thank you for the reply. "Submitter.group.name" is just used as an example. The goal is to pull an e-mail from a field three layers deep. Then take this e-mail and send a message to it. This is all based off of a record being changed within clearquest.

     

    here's the some rough pseudo code:

    if the record changes to said state

    get the e-mail string

    my $fieldValue2 = $entity->GetFieldStringValue("Associated_Actions.Assignee.email")

    send e-mail to ("fieldValue2");

     

    ----

     

     

    yes a query would be much easier, but the e-mail field is needed for a notification action upon the change state of a record.

    Based on my experience with the ClearQuest Email Notification package,  in complex cases, SQL Query works better. You can check some code examples here: http://cqadmin.org/wiki/Notification_Examples#Using_SQL_query

    Pavel

  • DonaldN
    DonaldN
    255 Posts

    Re: Using AdReferenceListField as a AdReferenceField

    ‏2013-10-22T00:14:50Z  

    Thank you for the reply. "Submitter.group.name" is just used as an example. The goal is to pull an e-mail from a field three layers deep. Then take this e-mail and send a message to it. This is all based off of a record being changed within clearquest.

     

    here's the some rough pseudo code:

    if the record changes to said state

    get the e-mail string

    my $fieldValue2 = $entity->GetFieldStringValue("Associated_Actions.Assignee.email")

    send e-mail to ("fieldValue2");

     

    ----

     

     

    yes a query would be much easier, but the e-mail field is needed for a notification action upon the change state of a record.

    I believe your original method should work if and only if all fields in the field path name are single-valued (design wise, not actual). Take the original sample "Submitter.groups.name", you need to make sure the fields "Submitter", "groups" (of Submitter), and "name" (of groups) are all single-valued, in other words, "Submitter" and "groups" have to be of the type REFERENCE (definitely not REFERENCE_LIST, otherwise you will get the said error), and "name" can be either REFERENCE or SHORT_STRING (or any other primitive types).

    If you look at the sample in ClearQuest InfoCenter, you will notice that it mentions "reference" only, no "reference list".

    http://pic.dhe.ibm.com/infocenter/cqhelp/v8r0m0/topic/com.ibm.rational.clearquest.apiref.doc/topics/r_examples_usngfieldpthnms.htm

    If for some reason one of the fields in the field path is multivalued, you have to loop through this field (regardless there are actually 0, one or more than one values returned). Or you can run a direct SQL query instead, as suggested above.

  • CQAdmin
    CQAdmin
    103 Posts

    Re: Using AdReferenceListField as a AdReferenceField

    ‏2013-10-23T07:07:57Z  

    Hello Matthew,

    I tried the same code and got the same error. It looks like CQ is not allowing/designed to go till that level using GetFieldStringValue or so.

    I tried another approach or a workaround, it worked. I have written this code "Default Value of the field" - "Owner'sGroupName". I can see the Owner's group name while submitting the record. -

    $CQSession = $entity->GetSession();
    $queryDefObj = $CQSession->BuildQuery("users");
    $queryDefObj->BuildField("groups.name");
    $operator = $queryDefObj->BuildFilterOperator($CQPerlExt::CQ_COMP_OP_EQ);

    # In the below line I am using "admin" as the owner. You can write line of code to get Owner's name in a variable and can use as a variable here

    $operator->BuildFilter("login_name",$CQPerlExt::CQ_COMP_OP_EQ,[ "admin" ]);

    $resultSetObj = $CQSession->BuildResultSet($queryDefObj);
    $resultSetObj->Execute();

    while ($resultSetObj->MoveNext() == $CQPerlExt::CQ_SUCCESS) {
    push(@choices,$resultSetObj->GetColumnValue(1));
    }

    # I was having only one Group, still taking it into an array and setting a field named "Owner's Group Name"

    $entity->SetFieldValue($fieldname, @choices);

     

    Thanks.