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

Key not Found Exception

$
0
0

Hello,

This is my code for fetching new_city entity records on account Entity but i got an error

 

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)

{
Entity entity = (Entity)context.InputParameters["Target"]as Entity;
if (entity.LogicalName == "account")
{
if (entity.Attributes.Contains("new_city") && entity.Attributes["new_city"] != null)
{
Guid cityId = (Guid)((EntityReference)entity.Attributes["new_city"]).Id;

String XmlFetch = @"<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>" +
"<entity name='new_city'>" +
"<attribute name='new_cityid'/>" +
"<attribute name='new_name'/>" +
"<attribute name='createdon'/>" +
"<order descending='false' attribute='new_name'/>" +
"<filter type='and'>" +
"<condition attribute='new_cityid' value='" + cityId + "' uitype='new_city' uiname='Indore' operator='eq'/>" +
"</filter>" +
"</entity>" +
"</fetch>";

EntityCollection collect = service.RetrieveMultiple(new FetchExpression(XmlFetch));
if (collect != null)
{
if (collect.Entities.Count==1)
{
Entity ci = collect.Entities[0];
{
Guid stateid = (Guid)((EntityReference)entity.Attributes["new_state"]).Id;
Guid countryid = (Guid)((EntityReference)entity.Attributes["new_country"]).Id;
//EntityReference staterefrence = (EntityReference)ci.Attributes["new_state"];
//EntityReference countryrefrence = (EntityReference)ci.Attributes["new_country"];
if (entity.Attributes.Contains("new_state"))
{
entity.Attributes.Add("new_state",stateid);
}
if (entity.Attributes.Contains("new_country"))
{
entity.Attributes.Add("new_country",countryid);
}
}
throw new InvalidPluginExecutionException("not data");
}

resolve this problem

thanx.


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images