Question

Filtering of one field by another in 5.4

To configure filtering of one field by another you should add filtration code into script-task after Init event in card page.

Example for filtering Contacts by selected Account:

Open Tools - Configuration section, open Card Page – Opportunity:

Look for names of the fields you want to link, for example we need to filter contacts by selected account:

Open process:

Find script-task after Init event:

Add delegate subscription into script-task:

 

Page.ContactEdit.PrepareLookupFilter += delegate (object sender, LookupEditEventArgs e)  
 {      
        if (!Page.AccountEdit.Value.Equals(Guid.Empty)) {
                Collectionstringobject>> filters = e.Filters;
                filters.Add(new Dictionarystringobject> { 
                                   {"comparisonType", FilterComparisonType.Equal}, 
                                   {"leftExpressionColumnPath", "Account.Id"},
                                   {"useDisplayValue", false}, 
                                   {"rightExpressionParameterValues", newobject[] {Page.AccountEdit.Value}}});
        }
};

 

Where

AccountEdit – name of the filtering field;

ContactEdit – name of the filtered field;

Account – name of the column in the object which will be compared with AccountEdit’s value;

LookupEditEventArgs – parameter, which passes information about the field:

         LookupEditEventArgs – if it is lookup field

         ComboBoxEditEventArgs – if it is drop down list

Then create event handler AccountEditChange card page designer:

Add next code into the handler:

Page.ContactEdit.Clear(); //if we have lookup field
Page. ContactEdit.ListPrepared = false//if we have drop down list

Note if handler was already been added, there is no need to create second, add code into existing.

After adding code publish the page.

If you need to filter result by multiple fields, then body of delegate should look like this:

var filters = e.Filters;
object value = Page.CountryEdit.Value;
Guid countryId = (value == null || value.ToString().Equals(string.Empty)) ?Guid.Empty : Guid.Parse(value.ToString());
value = Page.RegionEdit.Value;
Guid regionId = (value == null || value.ToString().Equals(string.Empty)) ?Guid.Empty : Guid.Parse(value.ToString());
if (countryId != Guid.Empty) {
        filters.Add(new Dictionarystringobject> {
                {"comparisonType", FilterComparisonType.Equal},
                {"leftExpressionColumnPath", "Country.Id"},
                {"useDisplayValue", false},
                {"rightExpressionParameterValues", new object[]{countryId}}});
}
if (regionId != Guid.Empty) {
        filters.Add(new Dictionarystringobject> {
                {"comparisonType", FilterComparisonType.Equal},
                {"leftExpressionColumnPath", "Region.Id"},
                {"useDisplayValue", false},
                {"rightExpressionParameterValues", new object[] {regionId}}});
}

 

Like 2

Like

0 comments
Show all comments