Answered by:
Post Create Plugin Get Entity ID

Question
-
I am trying to get the entity id from a post create plugin.
However I get an error saying "the key was not present in the dictionary"
This is the code I used:
sID = context.OutputParameters.Properties[
"id"].ToString();
can anyone help me plese?
Darren MerciecaWednesday, January 19, 2011 3:34 PM
Answers
-
The code looks fine to me. Can you make sure that it's not other message invoking your plug-in? To put it another way, you may want to check if your plugin has been correctly registered for the Post Create message of the entity that you are trying to listen to.
Daniel Cai | http://danielcai.blogspot.com- Proposed as answer by Daniel Cai - KingswaySoftMVP Wednesday, January 19, 2011 4:51 PM
- Marked as answer by darrmerc Wednesday, January 19, 2011 4:52 PM
Wednesday, January 19, 2011 4:05 PM
All replies
-
The code looks fine to me. Can you make sure that it's not other message invoking your plug-in? To put it another way, you may want to check if your plugin has been correctly registered for the Post Create message of the entity that you are trying to listen to.
Daniel Cai | http://danielcai.blogspot.com- Proposed as answer by Daniel Cai - KingswaySoftMVP Wednesday, January 19, 2011 4:51 PM
- Marked as answer by darrmerc Wednesday, January 19, 2011 4:52 PM
Wednesday, January 19, 2011 4:05 PM -
Not sure about plugin but this possible using CrmService:-
//************************* //Create Opportunity //************************* var oName = oFirstName + " " + oLastName + " from " + oCompanyName + " on " + oDate; var xml = "<?xml version='1.0' encoding='utf-8'?>" + "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" + " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" + GenerateAuthenticationHeader() + "<soap:Body>" + "<Create xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" + "<entity xsi:type='opportunity'>" + "<name>" + oName + "</name>" + "<new_accountid>" + AccountName + "</new_accountid>" + "<campaignid>" + oCampaign + "</campaignid>" + "<customerid type='contact'>" + ContactName + "</customerid>" + "<transactioncurrencyid>" + oCurrency + "</transactioncurrencyid>" + "<pricelevelid>" + oPricelevel + "</pricelevelid>" + "<new_handsetsrequired>" + oHSRequired + "</new_handsetsrequired>" + "<new_numberofexistinghandsets>" + oHSHave + "</new_numberofexistinghandsets>" + "</entity>" + "</Create>" + "</soap:Body>" + "</soap:Envelope>"; // Prepare the xmlHttpObject and send the request. var xHReq = new ActiveXObject("Msxml2.XMLHTTP"); xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false); xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Create"); xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xHReq.setRequestHeader("Content-Length", xml.length); xHReq.send(xml); var resultXml = xHReq.responseXML; //debugger; var errorCount = resultXml.selectNodes('//error').length; if (errorCount != 0) { var msg = resultXml.selectSingleNode('//description').nodeTypedValue; alert(msg); } else { var oOpportunity = resultXml.selectSingleNode("//CreateResult"); var URL = "/sfa/opps/edit.aspx?id={" + oOpportunity.nodeTypedValue + "}"; //alert(URL); window.open(URL, 'Opportunity', 'width=900, height=600'); } var OppId = "{" + oOpportunity.nodeTypedValue + "}"; var lookupItem = new Array(); lookupItem[0] = new LookupControlItem(OppId, 3, oName); crmForm.all.new_opportunityid.DataValue = lookupItem; } //********************************* //End of Create Contact Account Opportunity //*********************************
Regards FaisalWednesday, January 19, 2011 4:09 PM -
Also recommend you to post your entire code block. So that it will be easy to spot out the problem.
Regards
Vinoth
Wednesday, January 19, 2011 4:10 PM -
There was no problem with my code.
The error was occuring from another plugin registred on the same event.
Thanks
Darren
Darren MerciecaWednesday, January 19, 2011 4:48 PM -
Hi Darrmerc,
İn the post state try the following code or use the post Image
Guid sID = (Guid )context.OutputParameters["Id" ];
Regards,
Thursday, January 20, 2011 7:16 AM