locked
CRM 2011 - Modifying QueryExpression on RetrieveMultiple Message RRS feed

  • Question

  • Here is my scenario:

    I am trying to trap the RetrieveMultiple message and modify the QueryExpression it is using. Specifically, when clicked on Connections from left navigation of the Contact entity, all the connections created for that contact are retrieved.

    I need to modify the QueryExpression on RetrieveMultiple of Connections for contact to include connections created for that contact child opportunities.

    I hope this is clear. So far, I have got to the point that I can trap the message and look at the query being submitted in a Pre Operation plugin.

    Is there a smaple code you can point me to that shows me how to accomplish this?

    Your help is greatly appreciated.

    Friday, August 2, 2013 5:36 PM

Answers

  • You can modify the query by accessing the 'Query' parameter in the pre-retrievemultiple plugin:

    QueryExpression query = context.InputParameters["Query"] as QueryExpression;
    query.Criteria.AddCondition(new ConditionExpression());

    If you're also seeking guidance for how to construct your desired filter, you can first do a retrievemultiple on opportunities related to the contact (you might have to extract the contactId from the query), and then include the ID's of the opportunities in a condition using the 'In' operator.

    You would also want to make sure you're only modifying the contact connections retrievemultiple, so check for certain unique conditions before modifying the query.

    Hope that helps

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    • Marked as answer by Homayoun Niazi Saturday, August 3, 2013 10:28 PM
    Saturday, August 3, 2013 8:53 PM

All replies

  • You can modify the query by accessing the 'Query' parameter in the pre-retrievemultiple plugin:

    QueryExpression query = context.InputParameters["Query"] as QueryExpression;
    query.Criteria.AddCondition(new ConditionExpression());

    If you're also seeking guidance for how to construct your desired filter, you can first do a retrievemultiple on opportunities related to the contact (you might have to extract the contactId from the query), and then include the ID's of the opportunities in a condition using the 'In' operator.

    You would also want to make sure you're only modifying the contact connections retrievemultiple, so check for certain unique conditions before modifying the query.

    Hope that helps

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    • Marked as answer by Homayoun Niazi Saturday, August 3, 2013 10:28 PM
    Saturday, August 3, 2013 8:53 PM
  • Paul,

    Thank you so much. Yes, I was seeking guidance for how to construct my desired filter. 

    From my latest research I need to include the "Connections" created for opportunities associated with this contact along with the existing "Connections" for that contact.  I think I need to do some sort of Union to do this.

    I can do the retrievemultiple function call in the plugin to retrieve required data. Could you please provide me some advice and some sample code on how to modify the existing QueryExpression to get my desired result?

    I thank you very much for your time.

    I look forward to hearing back from you.

    Homayoun

    Saturday, August 3, 2013 10:01 PM
  • I read your comments again and I believe you already provided the answer.

    Thank you, Paul.

    Saturday, August 3, 2013 10:28 PM
  • Paul,

    Sorry to bother you again. One more thing:

    Once I get the opportunity guids from my retrievemultiple function call, how can I include them in the "In" clause you specified above.

    Does query expression "Values" property take list of Guids? How can I dynamically build my "In" Caluse?

    I appreciate your time.

    Homayoun

    Saturday, August 3, 2013 10:52 PM
  • The 'In' operator takes an array of objects, so you just need to cast your List<Guid> to object[]

    list.Cast<object>().ToArray()

    Hope that helps

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    Saturday, August 3, 2013 10:55 PM
  • One more thing, you'll want to do an 'OR' filter expression to say recordId == contactId OR recordId IN oppIds.

    I imagine the default query will have a condition for contactId already, so if you only add the 'IN' condition it will return no results (as it will try and find where recordId == contactId AND recordId IN oppIds.

    So you may have to reconstruct the whole query to include the OR condition and remove the default condition.

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    Saturday, August 3, 2013 11:47 PM
  • I can't thank you enough, Paul.

    I am amazed with this web site. Is this Microsoft related web site? I would love to have this kind of support (like what you provided) to help me grow and learn.

    Please advise.

    Homayoun

    Sunday, August 4, 2013 1:47 AM
  • Happy to help :)

    Yes this is a Microsoft site, but anyone can answer questions.

    Best of luck going forward

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    Sunday, August 4, 2013 2:50 AM
  • Microsoft, keep up the good work. I am a Microsoft fan and a former v-dash employee.

    Thank you so much, Paul. Untill later :)

    Homayoun

    Sunday, August 4, 2013 3:13 AM
  • Paul,

    So sorry to bother you gain. I hope you get this message and can respond today. I have been working on this today. I am stuck with reconstructing the whole query. Somehow the new OR condition doesn't work as you specified above so it seems like I have to reconstruct the whole query.

    I know how to build the query expression for this. I don't know how to replace the new one with the old one.

    Please advise.

    Thank you so much.

    Homayoun

    Sunday, August 4, 2013 8:11 PM
  • Paul,

    I got this to work. Thank you very much.

    Homayoun

    Sunday, August 4, 2013 9:44 PM