Skip to content

[Feature]: Additional dynamic filtering on PolyLookup #286

@cfharp

Description

@cfharp

Problem description

I would like to be able to apply a filter condition based on a value of another field (but not filter directly by the value of the field).
For example, if a multi-select option set has 123 selected, then apply a specific filter condition to the fetchxml.

Feature description

I did some quick testing and it seems like if we had custom helper functions registered in Handlebars, those could be used in the fetchxml.
A couple of examples include:

Handlebars.registerHelper('ifEq', function (a, b, options) {
  if (a == b) {
    return options.fn(this);
  }
  return options.inverse(this);
});
Handlebars.registerHelper('ifIn', function (a, list, options) {
  if (list?.indexOf(a) > -1) {
    return options.fn(this);
  }
  return options.inverse(this);
});

Which could then be used like:

<fetch>
  <entity name='ab_entity'>
    <attribute name='ab_name' />
    <order attribute='ab_name' descending='false' />
    <filter type='and'>
      <condition attribute='statecode' operator='eq' value='0' />
	  <filter type='or'>
	    {{#ifIn 123000000 ab_multiselect}}<condition attribute='ab_field1' operator='eq' value='1' />{{/ifIn}}
	    {{#ifIn 123000000 ab_multiselect}}<condition attribute='ab_field2' operator='eq' value='1' />{{/ifIn}}
      </filter>
    </filter>
  </entity>
</fetch>

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: feature 🚀A new capability or function needs to be added

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions