web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Party Id Through a QueryExpression

(0) ShareShare
ReportReport
Posted on by 230

Hi, 


I am trying to get the from email (from contact) from a list of email in a queue...  i am getting a key error and i'm not sure what i am doing wrong.

i pasted my code, i'm using standard fields in queueitem and email entities...

my ultimate goal is the get contact email, but for debugging purposed i'm setting a counter in a field i can display.

this works but it never finds any "parties"

    QueryExpression UserQry = new QueryExpression("queueitem"); // name of entity
    UserQry.ColumnSet = new ColumnSet("objecttypecode", "title", "sender","queueid","statecode","objectid"); // columns
    UserQry.Distinct = true; // not sure
    UserQry.NoLock = true; // not sure
    // conditions
    UserQry.Criteria.AddCondition("queueid", ConditionOperator.Equal, new Guid("b462b806-eabc-e411-80d0-00155d013314")); 
    UserQry.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);                                       
    // link entity (master/detail merged into one)
    LinkEntity linkEntityEmails = new LinkEntity()
    {
      LinkFromEntityName = "queueitem", 
      LinkFromAttributeName = "objectid",
      LinkToEntityName = "email",
      LinkToAttributeName = "activityid",
      JoinOperator = JoinOperator.LeftOuter,
      Columns = new ColumnSet("from","sender","subject"),
      EntityAlias = "Email"
    };                                        
    UserQry.LinkEntities.Add(linkEntityEmails);                                       
      //linkEntityEmails.LinkCriteria.AddCondition("subject", ConditionOperator.Equal, "Email Title"); // <- this does not work, not sure why
    EntityCollection Qlist = (EntityCollection)service.RetrieveMultiple(UserQry);
    foreach (Entity Email in Qlist.Entities)
    {
       if ((Email["Email.subject"] as AliasedValue).Value.ToString() == "TESTEMAIL") //NE PAS EFFACE")
       {                         
          //EntityCollection FromAddrs = (EntityCollection)Email["Email.from"]; //get an error?
          EntityCollection FromAddrs = Email.GetAttributeValue<EntityCollection>("Email.from");  //(EntityCollection)Email["Email.from"];
          if (FromAddrs != null && FromAddrs.Entities.Count > 0)
          {
              title = "count:" +FromAddrs.Entities.Count.ToString();             
          }
          else title ="not found";
      }
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi Anthony,

    Have you tried to debug your plug-in in Visual Studio? What do you see under the Attributes collection?

    Also, if you try retrieving all attributes ColumnSet = new ColumnSet(true) - does that bring in the required data?

    Regards,

    Radu

  • Anthony A Profile Picture
    230 on at

    I have not figured out how to debug straight from Visual Studio.  (i am using CRM2013)

    I have to compile my plugin then upload using plugin registration tool and they using the system jobs  / customs fields i populate and can figure out whats going on.

    I know its kinda lame, i followed the procedure in the SDK and it didnt work for me... (i'm very new to Visual Studio  / C#)

    I will try that.... (all columns) and see if i can retreive what i need!

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi,

    It is pretty easy.

    If you are using CRM OnPrem - you need to load the symbols in Visual Studio and then attach VS to the relevant process.

    If it is a

    - sandboxed (in isolation) plug-in then you need to attach it to the Sandbox Service

    - running with no isolation -> w3wp

    - async plug-in -> async service

    You put breakpoints in the code, where you want your execution to stop and once that is done, check the variables and see what they contain and built on top of that.

    You can also debug a plug-in using the profiler: community.dynamics.com/.../how-to-debug-plugins-using-profiler but if you are on OnPrem - i find attaching VS directly tot he process is easier.

    Hope this helps,

    Radu

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Anthony,

    It is not direct to get the from from the email record because it is stored in a different entity "Activity Party" so basically you are lookng for something this Queue >> Queue Item > Email >> Activity Party.

    If you just need the email address used in the email then you can use sender field which stores the email address.

    fromAddress = (Email["Email.sender"] as AliasedValue).Value.ToString();  

    Hope this helps.

  • Anthony A Profile Picture
    230 on at

    I didn't try Sender, I found the field in CRM but since  I couldn't get it on a form, I figured it might not be what i was looking for. (I might try it out and if it works simplify the code, since i have to do  (Email-> partylist -> contact) to get the email....

    I don't understand why using the query expression with LinkEntity  I could not read the "From"  "party list" but I could read the subject of the email.  - i tried a whole bunch of combination using the "AliasValue" ... but since never figured it out.

    I ended up removing the "link entity" part and put a fetch email info in the for each...  (i have the emailid through the querylist "objectid" ....)

    its probably more SQL intensive since its fetch multiple "single records" instead of a bunch in one heap, but we rarely have more than 10-15 emails in the queue so I guess its manageable....

  • Anthony A Profile Picture
    230 on at

    "you put breakpoints in the code, where you want your execution to stop and once that is done, check the variables and see what they contain and built on top of that.

    You can also debug a plug-in using the profiler: community.dynamics.com/.../how-to-debug-plugins-using-profiler but if you are on OnPrem - i find attaching VS directly tot he process is easier."

    I will try this for sure once at the ofifce next week, right now i'm over a VPN tunnel and even my Plugin Registration tool is not working (used to) I have a feeling my IT guys added some extra security somewhere... its very painfull running tests the way i'm doing it!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans