Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

Not Getting Entity Record Name

$
0
0

Hye,

i have created a plugin on create of phonecall, i have set the TO value in regarding field if it is lead , contact , account or systemuser.

on create it works perfectly but on update it updates the record in regarding but not setting the name and showing null.

can any one have any idea about it ? 

Code:

if (context.MessageName == "Update") {
                
                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                  
                    Entity PhoneCall = context.InputParameters["Target"] as Entity;
                    if (PhoneCall.Attributes.Contains("to"))
                    {
                        
                        string LogicalName = ((EntityReference)((EntityCollection)PhoneCall["to"]).Entities[0].Attributes["partyid"]).LogicalName;
                        Guid EntityGuid = ((EntityReference)((EntityCollection)PhoneCall["to"]).Entities[0].Attributes["partyid"]).Id;
                        string _name = ((EntityReference)((EntityCollection)PhoneCall["to"]).Entities[0].Attributes["partyid"]).Name;

                        if (LogicalName == "contact" || LogicalName == "account" || LogicalName == "systemuser" || LogicalName == "lead")
                        {
                            
                                EntityReference RegardingObject = new EntityReference();
                                RegardingObject.Id = EntityGuid;
                                RegardingObject.LogicalName = LogicalName;
                                RegardingObject.Name = _name;
                                if (PhoneCall.Attributes.Contains("regardingobjectid"))
                                {
                                    PhoneCall["regardingobjectid"] = RegardingObject;
                                }
                                else {

                                    PhoneCall.Attributes.Add("regardingobjectid", RegardingObject);
                                }
                            
                        }
                    }

                }



Viewing all articles
Browse latest Browse all 55831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>