Plugin for RetrieveMultiple and Execute message
-
Thursday, 16 December 2010 7:32 PMI am writing a plugin that will fire anytime there is a retrieve
multiple or execute message and decrypt the social security number
that is stored in the database. I have this working fine on the
window, but not in the grid. They want to be able to search by the
SSN. I've noticed that when I refresh the contacts it sometimes uses
the RetrieveMultiple code and sometimes the Execute code, but neither
seems to be updating the results. I've checked and the
RetrieveMultiple code decrypts the SSN correctly, but the data doesn't
make it to the front end. This is the code for the RetrieveMultiple:
BusinessEntityCollection results =
(BusinessEntityCollection)context.OutputParameters[ParameterName.BusinessEntityCollection];foreach (DynamicEntity result in
results.BusinessEntities)
{
if (result.Name ==
EntityName.contact.ToString())
{
string ssn =
(string)result.Properties["new_ssn"];result.Properties["new_ssn"] =
util.DecryptString(ssn);
}
}This is the code for the Execute message:
string result =
(string)context.OutputParameters.Properties["FetchXMLResult"];entityDoc.LoadXml(result);
XmlElement SSN = null;
XmlNodeList propertyList =
entityDoc.GetElementsByTagName("Property");
//pick apart each element of the XML we need here
to pass to the sproc to build the Event ID
foreach (XmlElement element in propertyList)
{
if (element.GetAttribute("Name").ToLower() ==
"new_ssn")
{SSN =
(XmlElement)element.GetElementsByTagName("Value")[0];
SSN.InnerText = element.InnerText;element.InnerText =
util.DecryptString(SSN.InnerText);
}
}The Execute code doesn't get past the line " if
(element.GetAttribute("Name").ToLower() == "new_ssn")" even though I
can see the new_ssn in the resultset. Any ideas?Thanks
Ben
- Moved by Kimberlee JohnsonMicrosoft Employee Thursday, 16 December 2010 7:42 PM Plugin question (From:Dynamics CRM)
All Replies
-
Friday, 17 December 2010 1:44 AMAre you able to show us the fetchml result? and is .GetAttribute("name") returning a value?
Kids don't try this at home! -
Friday, 17 December 2010 1:22 PM
This is an example from FetchXMLResult
<resultset morerecords="1" paging-cookie="<cookie page="1"><lastname last="LastName" first="&quot;FirstName&quot;" /><contactid last="{D10BEA07-54EC-DF11-A89A-005056992800}" first="{801B5051-50EC-DF11-A89A-005056992800}" /></cookie>"><result><new_address1state name="FL - Florida" formattedvalue="15">15</new_address1state><address1_city>Deerfield Beach</address1_city><new_statusid name="ACT" dsc="0">{31F20D8D-AFDB-DF11-A89A-005056992800}</new_statusid><new_regionid name="Eastern" dsc="0">{8539E44B-B2DB-DF11-A89A-005056992800}</new_regionid><lastname>LastName</lastname><new_ssn>x63Tbx7c2selgiL/BptVYHhIIWPeWl0i6lFtqvV6F1A=</new_ssn><contactid>{801B5051-50EC-DF11-A89A-005056992800}</contactid></result></resultset>
I added some logging after the "foreach (XmlElement element in propertyList)" to give me the .GetAttribute("name") for every element return. This loop isn't entered so apparently there isn't an XmlElement in propertyList. I'm not sure why that is the case since I can see the xml results in FetchXMLResult. I'm not an xml expert though so that code may not be right.
Thanks
Ben
-
Friday, 17 December 2010 2:03 PM
Ok I have modifed the code that handles the execute message to the following:
This successfully sets the node2.InnerText to the decrypted ssn. I have the decrypted data showing in the grid, but the find functionality isn't working for this field. Any idea how to get find to work on this field?string result = (string)context.OutputParameters.Properties["FetchXMLResult"]; entityDoc.LoadXml(result); string SSN = null; XmlNodeList propertyList = entityDoc.GetElementsByTagName("result"); foreach (XmlNode element in propertyList) { foreach (XmlNode node2 in element.ChildNodes) { if (node2.Name == "new_ssn") { SSN = node2.InnerText; node2.InnerText = util.DecryptString(SSN); util.WriteToAppLog(node2.InnerText); } } }
-
Sunday, 19 December 2010 3:37 AMHi Ben
Hook into the execute event, post synchronous on parent pipeline
Kids don't try this at home! -
Tuesday, 25 January 2011 4:00 PMModerator
If I understand correctly, you want a user to able to enter an unencrypted SSN in the Quick Find (or Advanced Find), and to get appropriately filtered results ?
If so, you'll need to hook into the pre-stage on the Execute message to modify the query to apply an appropriate filter. I see 2 options:
- For exact matches only, you could parse the FetchXml and encrypt the entered SSN. This should then match the appropriate record in the database, but could only work for exact matches, rather than pattern matches
- If you need a pattern match, then it all becomes a lot harder. I think you'd have to strip out the condition expression in the pre-stage so all records are initially returned from the database, then in the post-stage you'd have to decrypt each record in turn, and remove it from the resultset if it doesn't match. You can use the context.SharedVariables property bag to pass the filter from the pre to post-stage. You'll still get major problems due to CRM paging though
Microsoft CRM MVP - http://mscrmuk.blogspot.com http://www.excitation.co.uk- Marked As Answer by DavidJennawayMVP, Moderator Tuesday, 15 February 2011 4:31 PM
-
Friday, 18 May 2012 10:18 PM
Hi Ben,
How did you set back the results in the OutputParameters?
did you do something like?
context.OutputParameters.Properties["FetchXMLResult"] = modifiedXml;