locked
how to get campaignresponse customer type RRS feed

  • Question

  • Hi,

    I am retreiving campaign responses  attributes which also contains customer.

    i need to process the record only when customer type is "lead" only but i am unable to find the customer type.

    Please let me know how to find the customer type

     

    below is my code


                    ColumnSet cols = new ColumnSet();
                    QueryExpression query = new QueryExpression();

                    cols.Attributes = new string[] { "regardingobjectid","createdon","customer" };
                    query.EntityName = EntityName.campaignresponse.ToString();
                    OrderExpression oe = new OrderExpression();
                    oe.AttributeName = "createdon";
                    oe.OrderType = OrderType.Ascending;

                    // CREATE THE CONDITIONEXPRESSION.
                    // CREATE THE CONDITIONEXPRESSION FOR FIRSNAME ,LASTNAME ,HOME PHONE
                    ConditionExpression condition1 = new ConditionExpression();
                    condition1.AttributeName = "firstname";
                    condition1.Operator = ConditionOperator.Equal;
                    condition1.Values = new object[] { FirstName };

                    ConditionExpression condition2 = new ConditionExpression();
                    condition2.AttributeName = "lastname";
                    condition2.Operator = ConditionOperator.Equal;
                    condition2.Values = new object[] { LastName };

                    ConditionExpression condition3 = new ConditionExpression();
                    condition3.AttributeName = "stei_homephone";
                    condition3.Operator = ConditionOperator.Equal;
                    condition3.Values = new object[] { HomePhone };

                    FilterExpression filterPrincipal = new FilterExpression();

                    // SET THE PROPERTIES OF THE FILTEREXPRESSION.
                    filterPrincipal.FilterOperator = LogicalOperator.And;
                    filterPrincipal.Conditions
                                         = new ConditionExpression[] { condition1, condition2, condition3 };


                    // SET THE PROPERTIES OF THE QUERYEXPRESSION.                  
                    query.ColumnSet = cols;
                    query.Criteria = filterPrincipal;

                    // CREATE THE REQUEST OBJECT.

                    RetrieveMultipleRequest retrieive = new RetrieveMultipleRequest();

                    // SET THE PROPERTIES OF THE REQUEST OBJECT.

                    retrieive.Query = query;

                    // EXECUTE THE REQUEST.

                    RetrieveMultipleResponse retrieived = (RetrieveMultipleResponse)service.Execute(retrieive);

                    BusinessEntityCollection aLeads = retrieived.BusinessEntityCollection;
                    int i = aLeads.BusinessEntities.Count();
                    

                    if (aLeads.BusinessEntities.Length != 0)
                    {
                           id = ((((campaignresponse)(aLeads.BusinessEntities[i-1])).regardingobjectid)).Value;
                        campaignresponse entity = (campaignresponse)aLeads.BusinessEntities[i-1];
                        return id = entity.regardingobjectid.Value;

                    }

     

    Wednesday, June 2, 2010 9:16 AM

Answers

  • Customer field is of type party list.
    Hence we need to link to ActivityParty table to obtain the details.

    SQL Query :

    The SQL query for your requirement is as below

    Select
    FilteredActivityParty.activityid,participationtypemaskname, partyobjecttypecode 
    from FilteredActivityParty JOIN FilteredCampaignResponse
    ON FilteredActivityParty.activityid = FilteredCampaignResponse.activityid
    and FilteredActivityParty.participationtypemask = 11 --  participationtypemask = 11 --> Customer

    Query Expresion:

    The following condition must be added.

                LinkEntity link = new LinkEntity();
                link.LinkFromEntityName = EntityName.campaignresponse.ToString();
                link.LinkFromAttributeName = "activityid";
                link.LinkToEntityName = EntityName.activityparty.ToString();
                link.LinkToAttributeName = "activityid";

                query.LinkEntities = new LinkEntity[] { link };

                ConditionExpression customer = new ConditionExpression();
                customer.AttributeName = "participationtypemask";
                customer.Operator = ConditionOperator.Equal;
                customer.Values = new object[] { 11 }; //Filtering of type customer

                ConditionExpression lead = new ConditionExpression();
                lead.AttributeName = "partyobjecttypecode";
                lead.Operator = ConditionOperator.Equal;
                lead.Values = new object[] { 4 }; //Filtering of type Lead

                FilterExpression LinkfilterPrincipal = new FilterExpression();
                LinkfilterPrincipal.FilterOperator = LogicalOperator.And;
                LinkfilterPrincipal.Conditions = new ConditionExpression[] { customer, lead };
                query.ColumnSet = cols;

                link.LinkCriteria = LinkfilterPrincipal;


    Full Code :

                ColumnSet cols = new ColumnSet();          
                cols.Attributes = new string[] { "regardingobjectid", "createdon", "customer" };
                QueryExpression query = new QueryExpression();
                query.EntityName = EntityName.campaignresponse.ToString();
                OrderExpression oe = new OrderExpression();

                ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = "firstname";
                condition1.Operator = ConditionOperator.Equal;
                condition1.Values = new object[] { FirstName };

                ConditionExpression condition2 = new ConditionExpression();
                condition2.AttributeName = "lastname";
                condition2.Operator = ConditionOperator.Equal;
                condition2.Values = new object[] { LastName };

                ConditionExpression condition3 = new ConditionExpression();
                condition3.AttributeName = "stei_homephone";
                condition3.Operator = ConditionOperator.Equal;
                condition3.Values = new object[] { HomePhone };

                FilterExpression filterPrincipal = new FilterExpression();
                filterPrincipal.FilterOperator = LogicalOperator.And;
                filterPrincipal.Conditions = new ConditionExpression[] { condition1 };

                LinkEntity link = new LinkEntity();
                link.LinkFromEntityName = EntityName.campaignresponse.ToString();
                link.LinkFromAttributeName = "activityid";
                link.LinkToEntityName = EntityName.activityparty.ToString();
                link.LinkToAttributeName = "activityid";

                query.LinkEntities = new LinkEntity[] { link };

                ConditionExpression customer = new ConditionExpression();
                customer.AttributeName = "participationtypemask";
                customer.Operator = ConditionOperator.Equal;
                customer.Values = new object[] { 11 }; //Filtering of type customer

                ConditionExpression lead = new ConditionExpression();
                lead.AttributeName = "partyobjecttypecode";
                lead.Operator = ConditionOperator.Equal;
                lead.Values = new object[] { 4 }; //Filtering of type Lead

                FilterExpression LinkfilterPrincipal = new FilterExpression();
                LinkfilterPrincipal.FilterOperator = LogicalOperator.And;
                LinkfilterPrincipal.Conditions = new ConditionExpression[] { customer, lead };
                query.ColumnSet = cols;

                query.Criteria = filterPrincipal;
                link.LinkCriteria = LinkfilterPrincipal;

                RetrieveMultipleRequest retrieive = new RetrieveMultipleRequest();
                retrieive.Query = query;
                RetrieveMultipleResponse retrieived = (RetrieveMultipleResponse)service.Execute(retrieive);


    Regards
    Vinoth

    Wednesday, June 2, 2010 11:28 AM