locked
retrieve activitypointer RRS feed

  • Question

  • My contact have list of histories (activitypointer).  some activitypointer has regardingobjectid  as this contact id.  and others are not.   I checked these activity won't have regardingobjectid, they are emails and have to recipe as the this contact.

    But when i retrieve all actiitypointer through asp.net code,  how do i get contact history to include all of these two types?

    Appreciate for your help
    Tuesday, September 15, 2009 2:16 PM

Answers

  • Hi, Hesper.

    Try to use following code:

                QueryExpression query = new QueryExpression(EntityName.activitypointer.ToString());
                LinkEntity link = query.AddLink(EntityName.activityparty.ToString(), "activityid", "activityid", JoinOperator.Inner);
                link.LinkCriteria.AddCondition("partyid", ConditionOperator.Equal, <identifier of entity>);
                link.LinkCriteria.AddCondition("participationtypemask", ConditionOperator.NotEqual, 8);
                link.LinkCriteria.FilterOperator = LogicalOperator.And;
    
                query.ColumnSet = new AllColumns();
                query.Distinct = true;
    
                RetrieveMultipleRequest request = new RetrieveMultipleRequest();
                request.Query = query;
                request.ReturnDynamicEntities = true;
    
                BusinessEntityCollection collection = ((RetrieveMultipleResponse)service.Execute(request)).BusinessEntityCollection;
    


    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by hesper Thursday, September 17, 2009 3:37 PM
    Thursday, September 17, 2009 7:45 AM
    Moderator

All replies

  • Hi, Hesper.

    Could you give the code for your query? You have to loin to ActivityParty entity to retrieve all required records.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, September 15, 2009 2:32 PM
    Moderator
  • QueryExpression query = new QueryExpression();
                query.EntityName = ""activitypointer";
                
                    FilterExpression filter = new FilterExpression();
                    filter.Conditions = new ConditionExpression[filters.Count];
                    filter.FilterOperator = LogicalOperator.Or;
                   
                        ConditionExpression condition = new ConditionExpression();
                        condition.AttributeName = "regardingobjectid"
                        condition.Operator = ConditionOperator.In;
                        condition.Values = (string[])contact_id;
                        filter.Conditions.Add(condition);
                       
                query.Criteria = filter;
                query.ColumnSet = new AllColumns();
                RetrieveMultipleRequest request = new RetrieveMultipleRequest();
                request.Query = query;
                RetrieveMultipleResponse response = (RetrieveMultipleResponse)service.Executerequest);


    I know i could retrieve all history with records have "regardingobjectid"

    but i don't know how to retrieve the history without "regardingobjectid"

    thanks for any help
    Tuesday, September 15, 2009 2:41 PM
  • Hi.

    Try this code:

                QueryExpression query = new QueryExpression();
                query.EntityName = "activitypointer";
                
                query.ColumnSet = new AllColumns();
    
                TargetRollupActivityPointerByContact target = new TargetRollupActivityPointerByContact();
                target.ContactId = contact_id;
                target.Query = query;
    
                RollupRequest request = new RollupRequest();
                request.RollupType = RollupType.Related;
                request.Target = target;
                request.ReturnDynamicEntities = true;
    
                RollupResponse response = (RollupResponse)service.Execute(request);
    

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, September 15, 2009 3:15 PM
    Moderator
  • Andriy:
    Thanks for the reply. it is really helpful.

    I could get task, appointment, email, phone call from this query.

    i have another question.  could I get list which is not include regarding the contact id.

    For example:
    email from contact A to contact B  regarding set as contact C.
    Then i grab activity pointer of the C, i don't want to grab this email.  I only want to grab email which is from C or to C.

    similar for task, appointment, phone call...etc.
    I only want to grab the information  as major related but ignore whether the regarding is set as this contact.

    Appreciate for any help.



    Wednesday, September 16, 2009 3:51 PM
  • Hi, Hesper.

    Try to use this code:

    			QueryExpression query = new QueryExpression();
    			query.EntityName = "activitypointer";
    
    			query.ColumnSet = new AllColumns();
    			
    			query.Criteria = new FilterExpression();
    			query.Criteria.FilterOperator = LogicalOperator.Or;
    			query.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Null));
    			query.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.NotEqual, contact_id));
    
    			TargetRollupActivityPointerByContact target = new TargetRollupActivityPointerByContact();
    			target.ContactId = contact_id;
    			target.Query = query;
    
    			RollupRequest request = new RollupRequest();
    			request.RollupType = RollupType.Related;
    			request.Target = target;
    			request.ReturnDynamicEntities = true;
    
    			RollupResponse response = (RollupResponse)service.Execute(request);
    

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Wednesday, September 16, 2009 4:04 PM
    Moderator
  • still not exactly what i need

    for example:  email from A to C and regard about C. 
    then i cannot list this email in C's profile with this condition.

    i think have several situation  in C's profile
    1. Email From A To B regard about C   - don't want to include this email
    2. Email From A To C without regard - Include it
    3. Email From A To C regard about D   - include it
    4. Email From A to C regard about C - include it.

    Samething for task, phonecall, appointment, etc....
    query.Criteria.AddCondition(new
    
    
     ConditionExpression("regardingobjectid"
    
    
    , ConditionOperator.Null));
    query.Criteria.AddCondition(new ConditionExpression("regardingobjectid" , ConditionOperator.NotEqual, contact_id));


    Wednesday, September 16, 2009 5:47 PM
  • if i can't do it through the query, i think i will do it in the code.
    In the code I could check based on these situation and decide whether put it in the list


    Wednesday, September 16, 2009 6:06 PM
  • I'm working with Dynamics CRM about 9 months and the solution i have found to these problems is very simple: use direct access to CRM database. When i did this, my code to get data is much more simple and easy to understand, using the CRM api makes things more complicated.
    Wednesday, September 16, 2009 6:12 PM
  • Hi, Benjamin:
    what do you mean direct access to CRM database?  can you give a sample or link?


    I do find it's so hard to check from the code, because each activepointer won't have all attributes of email/task/appointment  etc.

    So i have to retrieve each object in order to check whether it's in from/to recipe and when my list get bigger. it takes forever to load my list.

    Wednesday, September 16, 2009 6:56 PM
  • Hi, Hesper.

    Try to use following code:

                QueryExpression query = new QueryExpression(EntityName.activitypointer.ToString());
                LinkEntity link = query.AddLink(EntityName.activityparty.ToString(), "activityid", "activityid", JoinOperator.Inner);
                link.LinkCriteria.AddCondition("partyid", ConditionOperator.Equal, <identifier of entity>);
                link.LinkCriteria.AddCondition("participationtypemask", ConditionOperator.NotEqual, 8);
                link.LinkCriteria.FilterOperator = LogicalOperator.And;
    
                query.ColumnSet = new AllColumns();
                query.Distinct = true;
    
                RetrieveMultipleRequest request = new RetrieveMultipleRequest();
                request.Query = query;
                request.ReturnDynamicEntities = true;
    
                BusinessEntityCollection collection = ((RetrieveMultipleResponse)service.Execute(request)).BusinessEntityCollection;
    


    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by hesper Thursday, September 17, 2009 3:37 PM
    Thursday, September 17, 2009 7:45 AM
    Moderator
  • If u know the CRM tables and fields, what i told is very simple. In your web application use ADO to access the CRM database, see what i did:

     I want to get the account name from an opportunity:

    string sql = @" SELECT 
    acc.new_nome_fantasia 
    FROM Opportunity opo
    JOIN Account acc ON opo.AccountId = acc.AccountId
    WHERE opo.OpportunityId = @id";
    SqlConnection conn = new SqlConnection(@"Data Source=YOURDATABASE; 
    User Id=USERTOACCESSDATA; Password=USERPASS; Initial Catalog=YOURCOMPANY_MSCRM");
    conn.Open();
    try
    {
    SqlCommand comando = new SqlCommand(sql, conn);
    comando.Parameters.Add(new SqlParameter("@id", idOportunidade));
    return comando.ExecuteScalar().ToString();
    }
    catch (Exception exe)
    {
    throw new InvalidPluginExecutionException(exe.Message);
    }

     

     

     You can do the same thing, open sql management studio, make your query, pass the parameters you need and done.

    Thursday, September 17, 2009 2:55 PM
  • If u know the CRM tables and fields, what i told is very simple. In your web application use ADO to access the CRM database, see what i did:

     I want to get the account name from an opportunity:

    string sql = @" SELECT 
    
    acc.new_nome_fantasia 
    
    FROM Opportunity opo
    
    JOIN Account acc ON opo.AccountId = acc.AccountId
    
    WHERE opo.OpportunityId = @id";
    
    SqlConnection conn = new SqlConnection(@"Data Source=YOURDATABASE; 
    
    User Id=USERTOACCESSDATA; Password=USERPASS; Initial Catalog=YOURCOMPANY_MSCRM");
    
    conn.Open();
    
    try
    
    {
    
    SqlCommand comando = new SqlCommand(sql, conn);
    
    comando.Parameters.Add(new SqlParameter("@id", idOportunidade));
    
    return comando.ExecuteScalar().ToString();
    
    }
    
    catch (Exception exe)
    
    {
    
    throw new InvalidPluginExecutionException(exe.Message);
    
    }

     

     

     You can do the same thing, open sql management studio, make your query, pass the parameters you need and done.


    ah, only remebering, i use this in my plugin, so you can use either the plugin and web apps.
    Thursday, September 17, 2009 3:00 PM
  • Andriy:
    this one works great.  I really appreciate for your help.
    Thursday, September 17, 2009 3:37 PM