Quantcast
Channel: Hiding in Plain Sight » customizations
Viewing all articles
Browse latest Browse all 5

Filtering Lookups and PartyLists in CRM 2011

$
0
0

I had a requirement to filter the Recipient (To) Party List based on the value in the Regarding (RegardingObjectID) field, and the converse to filter the Regarding lookup field based on the value of the Recipient field. In this case, there was a N:N relationship between Accounts and Contacts, and the Recipient always had to be a Contact filtered based on the Account shown in the Regarding Field, and the Regarding Field had to be filtered based on the Contact that was in the Recipient field.

My searching for the solution brought me to this blog: http://sliong.wordpress.com/2012/04/18/crm-2011-filtered-lookup-using-javascript/

var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}"; //Random GUID
var entityName = "account";
var viewDisplayName = "Accounts beginning with Abc";

var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='account'>" +
"<attribute name='name' />" +
"<attribute name='primarycontactid' />" +
"<attribute name='telephone1' />" +
"<attribute name='accountid' />" +
"<order attribute='name' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='name' operator='like' value='Abc%' />" +
"</filter>" +
"</entity>" +
"</fetch>";

var layoutXml = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
"<row name='result' id='accountid'>" +
"<cell name='name' width='300' />" +
"<cell name='primarycontactid' width='150' />" +
"<cell name='telephone1' width='100' />" +
"</row>" +
"</grid>";

Xrm.Page.getControl("new_accountid").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

Everything worked flawlessly, until I got to adapting it to the party field. At first, I thought the party field might have worked differently. Turned out that errors in the way that I adapted the code were to blame. This code worked just as well for the Party List field, as it had for the Lookup field. I just had to make sure I was using the correct FetchXML, passing the correct IDs, and setting it to the correct entity.


Filed under: Microsoft Dynamics CRM Tagged: CRM, customizations, Fetch XML, JavaScript, Microsoft, microsoft dynamics crm, Microsoft Dynamics CRM 2011, technology

Viewing all articles
Browse latest Browse all 5

Trending Articles