c# - CRM Dynamics Plugin Error : The given key was not present in the dictionary (When I trigger plugin on PhoneCall Create) -
i following error when fire plugin on phoncall create record in crm dynamics 2015,
public void execute(iserviceprovider serviceprovider) { itracingservice tracingservice = (itracingservice)serviceprovider.getservice(typeof(itracingservice));
ipluginexecutioncontext context = (ipluginexecutioncontext)serviceprovider.getservice(typeof(ipluginexecutioncontext)); iorganizationservicefactory servicefactory = (iorganizationservicefactory)serviceprovider.getservice(typeof(iorganizationservicefactory)); iorganizationservice service = servicefactory.createorganizationservice(context.userid); if (context.inputparameters.contains("target") && context.inputparameters["target"] entity) { entity entity = (entity)context.inputparameters["target"]; if (context.messagename == "create") { try { entity phonecall = new entity("phonecall"); int64 numbertocall = (int64)phonecall.attributes["new_identity"]; int64 receivecallon = (int64)phonecall.attributes["new_destination"]; var apikey = phonecall.attributes["new_apikey"].tostring(); int64 fid = (int64)phonecall.attributes["new_fid"]; guid phoneresponse = service.create(phonecall); basichttpbinding binding = new basichttpbinding(); binding.name = "basichttpbinding_iservice1"; binding.hostnamecomparisonmode = hostnamecomparisonmode.strongwildcard; binding.messageencoding = wsmessageencoding.text; binding.transfermode = transfermode.buffered; binding.usedefaultwebproxy = true; binding.security.mode = basichttpsecuritymode.transportcredentialonly; binding.security.transport.clientcredentialtype = httpclientcredentialtype.windows; binding.security.message.clientcredentialtype = basichttpmessagecredentialtype.username; binding.sendtimeout = new timespan(0, 10, 0); endpointaddress endpointaddress = new endpointaddress("http://localhost:62009/service1.svc"); servicereference1.service1client client = new servicereference1.service1client(binding, endpointaddress); client.clientcredentials.windows.allowedimpersonationlevel = system.security.principal.tokenimpersonationlevel.impersonation; client.channelfactory.credentials.windows.clientcredential = new system.net.networkcredential("mscrm\\thabiso", "1pft?mg6bscu?g", "mscrm0"); client.webcall(numbertocall, receivecallon, apikey, fid); } catch (faultexception<organizationservicefault> ex) { tracingservice.trace("myplugin: {0}", ex.tostring()); throw; } }
i believe answer phonecall record doesn't contain 1 of fields referring to. , doesn't contain values... because instantiate new instance of entity field values not appear nowhere... suggest delete line
entity phonecall = new entity("phonecall"); and replace phonecall entity in lines:
int64 numbertocall = (int64)phonecall.attributes["new_identity"]; int64 receivecallon = (int64)phonecall.attributes["new_destination"]; var apikey = phonecall.attributes["new_apikey"].tostring(); int64 fid = (int64)phonecall.attributes["new_fid"]; not sure why want create 1 phonecall after... please explai scenario?
Comments
Post a Comment