Answered by:
key not found into dictionary (crm 2015)

Question
-
Hi,
I developed a plugin which generate randomly a custom number . I add this number to serviceappointment attribute.
here is code:
Entityentity = (Entity)context.InputParameters["Target"];
if(context.MessageName == "Create")
{
log.WriteEntry(
"Création : ");
stringgenerate = generationSAnum(service);//GenerateAccess_numserviceappointement(service);
entity.Attributes.Add(
"access_numserviceappointement", generate);
log.WriteEntry(
"Génération de l'ID pour l'activité de service : "+ generate);
}
When i create an serviceappointment by dynamics crm 2015 directly, on save i had this error :
La clé donnée était absente du dictionnaire.
Before i had another error about planing:
i tried to replan or to ignore and save. and i had this error:
thanks for help
Regards
Friday, April 1, 2016 3:16 PM
Answers
-
Hi
I changed the plugin's event pipeline stage to pre-operation.
Now it's ok.
Thanks
Regards
- Marked as answer by dc74 Wednesday, May 4, 2016 8:01 AM
Wednesday, May 4, 2016 8:01 AM
All replies
-
What data type is attribute scc_opportunityproductsandservices ? is it just a text feild or number field ? what kind of CRM environment you are working with? online or on prem ?Friday, April 1, 2016 6:39 PM
-
Small tip - you post errors that use French? I don't know French so I can't understand that error. If you post an error - post translation.
Dynamics CRM MVP
Read My blog
Subscribe for one of my coursesSaturday, April 2, 2016 9:07 AMModerator -
hi thanks for reply,
"the given key was not present in the dictionary" , this is a translation Andrii,.
Dynamics crm 2015 (7.0.2.53) on-premise , Xin jin. where do you see scc_opportunityproductsandservices attribute?
Regards
- Edited by dc74 Monday, April 4, 2016 8:54 AM absent to not present
Monday, April 4, 2016 7:54 AM -
Hi,
What happens if you just put "test" instead of generate (the string attribute) in the add attributes? Just trying to see which key that is missing.
Regards
Rickard Norström Developer CRM-Konsulterna
http://www.crmkonsulterna.se
Swedish Dynamics CRM Forum: http://www.crmforum.se
My Blog: http://rickardnorstrom.blogspot.seMonday, April 4, 2016 10:44 AM -
This post gives information about the most likely source of this error. Nothing in the code you've posted looks to be an issue, so it is more likely something in your generationSAnum method
What event and stage is the plugin registered on ?
Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
Monday, April 4, 2016 11:47 AMModerator -
thanks nothing really wrong in generationSAnum.
I'm debugging but i think the problem is into the specific code of plugin execute method.
here is the sample:
if
((entity.Attributes.Contains("access_datedbutaprsmidi")) || (entity.Attributes.Contains("access_datefinaprsmidi")) || (entity.Attributes.Contains("scheduledend")) || (entity.Attributes.Contains("scheduledstart")))
{
DateTimematDeb2 = (DateTime)entity.Attributes["scheduledstart"];
DateTimematFin2 = (DateTime)entity.Attributes["scheduledend"];
DateTimeapremDeb2 = (DateTime)entity.Attributes["access_datedbutaprsmidi"];
DateTimeapremFin2 = (DateTime)entity.Attributes["access_datefinaprsmidi"];
log.WriteEntry(
"access_datedbutaprsmidi ,...: ");
TimeSpandureeMatin = matFin2 - matDeb2;
TimeSpandureeAprem = apremFin2 - apremDeb2;
TimeSpandureeTotal = dureeMatin + dureeAprem;
og.WriteEntry(
"timespan ,...: ");
intdays = dureeTotal.Days;
inthour = days * 12;
hour = hour + dureeTotal.Hours;
intminutes = hour * 60;
minutes = minutes + dureeTotal.Minutes;
intnumber = 0;
number = minutes;
log.WriteEntry(
" La durée : "+ number);
entity.Attributes.Add(
"actualdurationminutes", number);
entity.Attributes.Add(
"access_duree", number);
log.WriteEntry(
"Durée de l'activité de service"+ entity.Attributes["access_numserviceappointement"].ToString() + " mise à jour : "+ number);
}
Monday, April 4, 2016 2:09 PM -
Yes, that seems like it could generate issues. You're checking if any of four fields are available and then getting all four, you need to have an is-this-available check for each input.
Regards
Rickard Norström Developer CRM-Konsulterna
http://www.crmkonsulterna.se
Swedish Dynamics CRM Forum: http://www.crmforum.se
My Blog: http://rickardnorstrom.blogspot.seMonday, April 4, 2016 2:39 PM -
Hi
I changed the plugin's event pipeline stage to pre-operation.
Now it's ok.
Thanks
Regards
- Marked as answer by dc74 Wednesday, May 4, 2016 8:01 AM
Wednesday, May 4, 2016 8:01 AM