Plugin for RetrieveMultiple and Execute message

Traitée Plugin for RetrieveMultiple and Execute message

  • jeudi 16 décembre 2010 19:32
     
     
    I 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

Toutes les réponses

  • vendredi 17 décembre 2010 01:44
     
     
    Are you able to show us the fetchml result? and is .GetAttribute("name") returning a value?
    Kids don't try this at home!
  • vendredi 17 décembre 2010 13:22
     
     

    This is an example from FetchXMLResult

    <resultset morerecords="1" paging-cookie="&lt;cookie page=&quot;1&quot;&gt;&lt;lastname last=&quot;LastName&quot; first=&quot;&amp;quot;FirstName&amp;quot;&quot; /&gt;&lt;contactid last=&quot;{D10BEA07-54EC-DF11-A89A-005056992800}&quot; first=&quot;{801B5051-50EC-DF11-A89A-005056992800}&quot; /&gt;&lt;/cookie&gt;"><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

  • vendredi 17 décembre 2010 14:03
     
      A du code

    Ok I have modifed the code that handles the execute message to the following:

     

    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);
        }
       }
       }
    
    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?
  • dimanche 19 décembre 2010 03:37
     
     
    Hi Ben

    Hook into the execute event, post synchronous on parent pipeline
    Kids don't try this at home!
  • mardi 25 janvier 2011 16:00
    Modérateur
     
     Traitée

    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:

    1. 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
    2. 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
  • vendredi 18 mai 2012 22:18
     
     

    Hi Ben,

    How did you set back the results in the OutputParameters?

    did you do something like?

    context.OutputParameters.Properties["FetchXMLResult"] = modifiedXml;