Advanced Find, in its current form, doesn’t have the capability to do a true “In” condition for text, datetime and numbers. For example this is how you would really do an “In” condition for a text field.
However the above condition would not return any results, as Advanced Find doesn’t allow separating valid values with a semi-colon. Query like the one above, has to be actually be done like the screenshot below.
This is actually clunky and involves too many clicks. The query capability in Advanced Find also differs to what the workflow condition offers. For e.g. you can do a true “In” condition in workflow editor. The workflow condition builder uses a similar UI to Advanced Find, but it also displays a “In” condition for text attribute, which is not displayed in the Advanced Find.
Bookmarklet Solution
In order to do a “in” condition, where the target values are separated by semi-colons, you can use the bookmarklet below.
Unminified code
var contentPanel = $('#crmContentPanel > iframe'); if (contentPanel && contentPanel.length > 0) { var targetFrame = contentPanel[0].contentWindow; var isFetchModified = false; targetFrame.ExecuteQuery(); var xml = targetFrame.$get("FetchXml").value; var xmlDoc = $.parseXML(xml), $xml = $(xmlDoc); $xml.find('condition[value]').each(function (i, d) { var inCondition = ''; var multipleValues = $(d).attr('value'); if (multipleValues.indexOf(';') === -1) return; multipleValues.split(';').forEach(function (c) { inCondition += ('<value>' + c + '</value>'); }); $(d).attr('operator', 'in'); $(d).removeAttr('value'); $(d).html(inCondition); isFetchModified = true; }); if (isFetchModified) { targetFrame.$get("FetchXml", $get("resultRender")).value = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">' + xmlDoc.documentElement.innerHTML + '</fetch>'; } targetFrame.changeArea(targetFrame.ResultsPage); targetFrame.$get('resultRender').submit(); } else { alert('Cannot locate Advanced Find Frame'); } void 0;
Minified code for bookmark bar
javascript:var contentPanel=$('#crmContentPanel > iframe');if(contentPanel&&contentPanel.length>0){var targetFrame=contentPanel[0].contentWindow;var isFetchModified=false;targetFrame.ExecuteQuery();var xml=targetFrame.$get("FetchXml").value;var xmlDoc=$.parseXML(xml),$xml=$(xmlDoc);$xml.find('condition[value]').each(function(i,d){var inCondition='';var multipleValues=$(d).attr('value');if(multipleValues.indexOf(';')===-1) return;multipleValues.split(';').forEach(function(c){inCondition+=('<value>'+c+'</value>');});$(d).attr('operator','in');$(d).removeAttr('value');$(d).html(inCondition);isFetchModified=true;});if(isFetchModified){targetFrame.$get("FetchXml",$get("resultRender")).value='<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">'+xmlDoc.documentElement.innerHTML+'</fetch>';} targetFrame.changeArea(targetFrame.ResultsPage);targetFrame.$get('resultRender').submit();}else{alert('Cannot locate Advanced Find Frame');} void 0;
You basically continue to use the “equal” condition and then separate the valid values with semi-colon. Run the bookmarklet after that and the “equal” condition will be converted into a “in”. This currently works only for text fields. Datetime and number fields have additional format validations, hence it is not possible to use “;” to separate out the values.
I have tested this bookmarklet in CRM Online and CRM2015 with Firefox and Chrome.
Known Issues
A javascript error pops up before the results are displayed in Firefox. This can be ignored as the correct results are shown.
Hi, Does this Bookmarklet work with CRM 2011? I have tried it but keep getting ‘$’ is undefined. Can you help please?
$ is a reference to the jQuery library the CRM internally users. I don’t believe CRM2011 has a reference to jQuery. This script could probably be rewritten to use plain JavaScript i.e. document.querySelector, document.querySelectorAll, but I don’t have a CRM2011 instance to test/develop against.
Thanks Natraj, I found a tool to add the required script which checks if the JQuery is available and loads it, if not. http://benalman.com/projects/run-jquery-code-bookmarklet/
I’ve got it working in Chrome now (but not IE). Thanks for the great post!
That is great Emma. π
Hello Natraj, that Bookmarklet solution is very creative β thanks so much. Interesting that Microsoft implemented the βInβ condition elsewhere in Dynamics but failed to place it into Advanced Find where it would be most useful (at least for me). So one limitation with this solution is that the text field where the multiple βInβ values are entered (555-0104;555-0103;555-0100 in your example above) has a fixed length, so the number of comma-separated values could be quite small. In my case, the field I want to apply to solution to has an 100-character limit, so I can only enter a handful of filter cases, where ideally I would apply a few hundred.
Do you have any suggestions about how to remove this limitation? Iβm not a javascript expert by any means, but perhaps loading the filter values from an external text file would be a viable option. Thanks again!
If this is the case, it is easier to contruct the view or even just query the entity using XrmToolBox’s FetchXML Builder. The bookmarklet is easier for <20 "in" conditions.
Hey Natraj,
Iβve downloaded the FetchXML Builder and what I want to do is download consumers with a specific list of SS Numbers. I have about 30 different SS Numbers and each number is tied to a record. I obviously cant do an Advanced Find with 30 lines. How can I code my fetch XML view to allow me to add 30 different numbers?
Thanks,
SB
Iβm new to this so where do you copy this bookmarklet solution (unminified code) and how do you execute it?
You have to drag and drop the code into to the bookmark bar. When you you click the bookmark the code will execute on the current page. Refer https://support.mozilla.org/en-US/kb/bookmarklets-perform-common-web-page-tasks for general info about bookmarklets.