Mashup/LES – Related search and changing view while searching.

I accidently discovered a while back that I could use the TargetKey to set views and sorting orders.
This was followed up by another small indecent, which led to another discovery.
Did you know that you are able change the view after a LES search has been performed and keep the current hits?
I will also share how you can perform a related search with LES from a mashup. ( I will not share how to do all the setup, it’s primary just getting the query right)
When combing all these, I believe you can create quite a powerful tool.

Setting the sorting order:

Very simple, but for some unknown.  Just use the TargetKey to set the value.

<mashup:Event TargetName=”MMS200″ SourceEventName=”Click” TargetEventName=”Apply”>
<mashup:Parameter TargetKey=”WWQTTP” Value=”5″ />
</mashup:Event>

Changing the view can be done in multiple ways, here is an example where it’s done from a ComboBox.

<ComboBox Name="ItemMasterChangeView" MinWidth="85" MinHeight="20" MaxWidth="85" MaxHeight="70" Margin="5">
             <mashup:Event.SelectionChanged>
                <mashup:Events>
                   <mashup:Event SourceEventName="SelectionChanged" TargetName="MMS200" TargetEventName="Apply">
                      <mashup:Event.Conditions>
                         <mashup:Conditions>
                            <mashup:Condition TargetKey="Value" SourceValue="{Binding ElementName=ItemMasterChangeView, Path=SelectedIndex}" TargetValue="1" Operator="Equal" />
                         </mashup:Conditions>
                      </mashup:Event.Conditions>
                      <mashup:Parameter TargetKey="WWFACI" Value="100" />
                      <mashup:Parameter TargetKey="WWWHLO" Value="100" />
                      <mashup:Parameter TargetKey="WOPAVR" Value="{Binding ElementName=ONHAND, Path=Content}" />
                   </mashup:Event>

                   <mashup:Event SourceEventName="SelectionChanged" TargetName="MMS200" TargetEventName="Apply">
                      <mashup:Event.Conditions>
                         <mashup:Conditions>
                            <mashup:Condition TargetKey="Value" SourceValue="{Binding ElementName=ItemMasterChangeView, Path=SelectedIndex}" TargetValue="2" Operator="Equal" />
                         </mashup:Conditions>
                      </mashup:Event.Conditions>
                      <mashup:Parameter TargetKey="WWFACI" Value="100" />
                      <mashup:Parameter TargetKey="WWWHLO" Value="100" />
                      <mashup:Parameter TargetKey="WOPAVR" Value="{Binding ElementName=WHS, Path=Content}" />
                   </mashup:Event>
                </mashup:Events>
             </mashup:Event.SelectionChanged>

             <ComboBoxItem Name="BLANK" Content="" />
             <ComboBoxItem Name="ONHAND" Content="ONHAND" />
             <ComboBoxItem Name="WHS" Content="WHS" />
          </ComboBox>

NOTE: CHANGING SORTING ORDER OR VIEW MIGHT GIVE YOU A FATAL ERROR IN SOME OF THE PREVIOUS VERSIONS OF M3.
I don’t know which version the fix came in, but we recently had a upgrade of our environment and it now runs without problem, so far.
However, if you receive an error message, try setting the sorting order with filter 1 or higher, for some strange reason it only used to crash if the filter was set to 0.

Related search – creating the string.

There might be other ways to do this, so if you solved this previously in any other way I hope you are willing to share.
I will show you two different ways you can concatenate text to get the string you need.

1. Provide input to RespText, and using the MultiBinding will get yourself a string looking like this:
related:[ITEM_RESP(“input”)]:

<TextBox Name="RespText"  Text=""   />
<TextBox Name="RespDummy1" Text="related:[ITEM_RESP(&quot;"  Visibility="Hidden" />
  <TextBox Name="RespDummy2" Text="&quot;)]" Visibility="Hidden" />

    <TextBox Name="ItemRespSearch"  Visibility="Hidden">
       <TextBox.Text>
          <MultiBinding StringFormat="{}{0}{1}{2}">
             <Binding ElementName="RespDummy1" Path="Text" />
             <Binding ElementName="RespText" Path="Text" />
             <Binding ElementName="RespDummy2" Path="Text" />
          </MultiBinding>
       </TextBox.Text>
    </TextBox>

2. The other way is using the run command to concatenate.
This was unknown for me until a week ago, but Heiko was nice and shared it .

In the end, both will give you the same output.

</pre>
<TextBox Name="ItemTypeText" Text=""  />

<TextBlock Name="ItemTypeSearch" Visibility="Hidden">
       <TextBlock.Inlines>
         <Run Text="related:[ITEM_ITTY(&quot;" />
         <Run Text="{Binding ElementName=ItemTypeText,Path=Text}" />
         <Run Text="&quot;)]" />
       </TextBlock.Inlines>
     </TextBlock>

You have to add the string query to the TargetKey itself. If you put it as the value you might get some bad output.
You can set the TargetKey to “Query” and the string as value, but that will kill all your other inputs.

<Button Content="Search" Margin="0,0,0,0" Style="{DynamicResource styleButtonPrimaryMashup}">
             <Button.CommandParameter>
                <mashup:Events>
                   <mashup:Event SourceEventName="Click" TargetName="MMS200" TargetEventName="Search">
                      <mashup:Parameter TargetKey="FUDS" Value="{Binding Path=Text, ElementName=NameText}" />
                       <mashup:Parameter TargetKey="{Binding Path=Text, ElementName=ItemRespSearch}" Value="{Binding Path=Text, ElementName=ItemRespCheck}" />
                       <mashup:Parameter TargetKey="{Binding Path=Text, ElementName=ItemTypeSearch}" Value="{Binding Path=Text, ElementName=ItemTypeCheck}" />
                 </mashup:Event>

As you can see I am binding some values.
If the Value is blank the search will not be performed, so I’m just using this to check for any input.

If there is any input to the “RespText” the value will be set to ‘;’ .
You can use standard mashup conditions instead of the MultiDataTrigger as shown below.

<TextBox Name="ItemRespCheck" Visibility="Hidden">
       <TextBox.Style>
       <Style x:Key="ItemRespCheck" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
          <Setter Property="Text" Value=";" />
          <Style.Triggers>
             <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                   <Condition Binding="{Binding ElementName=RespText, Path=Text}" Value="" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Text" Value="" />
             </MultiDataTrigger>
          </Style.Triggers>
       </Style>
    </TextBox.Style>
    </TextBox>

And the final string query will be like this if you provide input to all 3.

FUDS:(A*) related:[ITEM_RESP(“141254”)]:(;) related:[ITEM_ITTY(“031”)]:(;)
If you are trying and failing with this, I strongly recommand using Fiddler or similar to see what output the mashup sends.

Attached is a full sample containing both the related search and changing view/sorting orders option.
You probably have to change some of the static values I’ve added to make it work.

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="clr-namespace:Mango.UI.Controls;assembly=Mango.UI" xmlns:mashup="clr-namespace:Mango.UI.Services.Mashup;assembly=Mango.UI" xmlns:m3="clr-namespace:MForms.Mashup;assembly=MForms">
    <Grid.Resources>
    </Grid.Resources>

    <Grid.ColumnDefinitions>
       <ColumnDefinition Width="*" />

    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
       <RowDefinition Height="30" />
       <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
          <TextBlock Text="Name:" />
          <TextBox Name="NameText" MaxWidth="80" MinWidth="80" />
          <TextBlock Text="Item responsible:" />
          <TextBox Name="RespText" Text="" MaxWidth="80" MinWidth="80" />
          <TextBlock Text="Item Type:" />
          <TextBox Name="ItemTypeText" Text="" MaxWidth="80" MinWidth="80" />

          <Button Content="Search" Margin="0,0,0,0" Style="{DynamicResource styleButtonPrimaryMashup}">
             <Button.CommandParameter>
                <mashup:Events>
                   <mashup:Event SourceEventName="Click" TargetName="MMS200" TargetEventName="Search">
                      <mashup:Parameter TargetKey="FUDS" Value="{Binding Path=Text, ElementName=NameText}" />
                         <mashup:Parameter TargetKey="{Binding Path=Text, ElementName=ItemRespSearch}" Value="{Binding Path=Text, ElementName=ItemRespCheck}" />
                          <mashup:Parameter TargetKey="{Binding Path=Text, ElementName=ItemTypeSearch}" Value="{Binding Path=Text, ElementName=ItemTypeCheck}" />
                   </mashup:Event>

                      <mashup:Event TargetName="MMS200" SourceEventName="Click" TargetEventName="Apply">
                      <mashup:Event.Conditions>
                         <mashup:Conditions>
                            <mashup:Condition SourceValue="{Binding Path=Text, ElementName=RespText}" TargetValue="" Operator="Equal" />
                         </mashup:Conditions>
                      </mashup:Event.Conditions>
                      <mashup:Parameter TargetKey="WWQTTP" Value="7" />
                   </mashup:Event>

                      <mashup:Event TargetName="MMS200" SourceEventName="Click" TargetEventName="Apply">
                      <mashup:Event.Conditions>
                         <mashup:Conditions>
                            <mashup:Condition SourceValue="{Binding Path=Text, ElementName=RespText}" TargetValue="" Operator="NotEqual" />
                         </mashup:Conditions>
                      </mashup:Event.Conditions>
                      <mashup:Parameter TargetKey="WWQTTP" Value="5" />

                   </mashup:Event>

                </mashup:Events>
             </Button.CommandParameter>
          </Button>

          <TextBlock Text="View" HorizontalAlignment="Right" />

          <ComboBox Name="ItemMasterChangeView" MinWidth="85" MinHeight="20" MaxWidth="85" MaxHeight="70" Margin="5">
             <mashup:Event.SelectionChanged>
                <mashup:Events>
                   <mashup:Event SourceEventName="SelectionChanged" TargetName="MMS200" TargetEventName="Apply">
                      <mashup:Event.Conditions>
                         <mashup:Conditions>
                            <mashup:Condition TargetKey="Value" SourceValue="{Binding ElementName=ItemMasterChangeView, Path=SelectedIndex}" TargetValue="1" Operator="Equal" />
                         </mashup:Conditions>
                      </mashup:Event.Conditions>
                      <mashup:Parameter TargetKey="WWFACI" Value="100" />
                      <mashup:Parameter TargetKey="WWWHLO" Value="100" />
                      <mashup:Parameter TargetKey="WOPAVR" Value="{Binding ElementName=ONHAND, Path=Content}" />
                   </mashup:Event>

                   <mashup:Event SourceEventName="SelectionChanged" TargetName="MMS200" TargetEventName="Apply">
                      <mashup:Event.Conditions>
                         <mashup:Conditions>
                            <mashup:Condition TargetKey="Value" SourceValue="{Binding ElementName=ItemMasterChangeView, Path=SelectedIndex}" TargetValue="2" Operator="Equal" />
                         </mashup:Conditions>
                      </mashup:Event.Conditions>
                      <mashup:Parameter TargetKey="WWFACI" Value="100" />
                      <mashup:Parameter TargetKey="WWWHLO" Value="100" />
                      <mashup:Parameter TargetKey="WOPAVR" Value="{Binding ElementName=WHS, Path=Content}" />
                   </mashup:Event>
                </mashup:Events>
             </mashup:Event.SelectionChanged>
             <ComboBoxItem Name="BLANK" Content="" />
             <ComboBoxItem Name="ONHAND" Content="ONHAND" />
             <ComboBoxItem Name="WHS" Content="WHS" />

          </ComboBox>

    </StackPanel>

    <TextBox Name="RespDummy1" Text="related:[ITEM_RESP(&quot;" Grid.Row="0" Visibility="Hidden" />
    <TextBox Name="RespDummy2" Text="&quot;)]" Visibility="Hidden" />

    <TextBox Name="ItemRespSearch" Grid.Row="0" Grid.Column="3" Visibility="Hidden">
       <TextBox.Text>
          <MultiBinding StringFormat="{}{0}{1}{2}">
             <Binding ElementName="RespDummy1" Path="Text" />
             <Binding ElementName="RespText" Path="Text" />
             <Binding ElementName="RespDummy2" Path="Text" />
          </MultiBinding>
       </TextBox.Text>
    </TextBox>

    <TextBlock Name="ItemTypeSearch" Visibility="Hidden">
       <TextBlock.Inlines>
         <Run Text="related:[ITEM_ITTY(&quot;" />
         <Run Text="{Binding ElementName=ItemTypeText,Path=Text}" />
         <Run Text="&quot;)]" />
       </TextBlock.Inlines>
     </TextBlock>

       <TextBox Name="ItemRespCheck" Visibility="Hidden">
       <TextBox.Style>
       <Style x:Key="ItemRespCheck" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
          <Setter Property="Text" Value=";" />
          <Style.Triggers>
             <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                   <Condition Binding="{Binding ElementName=RespText, Path=Text}" Value="" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Text" Value="" />
             </MultiDataTrigger>
          </Style.Triggers>
       </Style>
    </TextBox.Style>
    </TextBox>

       <TextBox Name="ItemTypeCheck" Visibility="Hidden">
       <TextBox.Style>
       <Style x:Key="ItemTypeCheck" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
          <Setter Property="Text" Value=";" />
          <Style.Triggers>
             <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                   <Condition Binding="{Binding ElementName=ItemTypeText, Path=Text}" Value="" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Text" Value="" />
             </MultiDataTrigger>
          </Style.Triggers>
       </Style>
    </TextBox.Style>
    </TextBox>

    <m3:ListPanel Name="MMS200" Grid.Row="1" IsListHeaderVisible="True" IsListHeaderExpanded="True">
       <m3:ListPanel.Events>
          <mashup:Events>
             <mashup:Event SourceEventName="Startup">
                <mashup:Parameter TargetKey="MBCONO" />
                <mashup:Parameter TargetKey="MBWHLO" />
                <mashup:Parameter TargetKey="MBITNO" />
                <mashup:Parameter TargetKey="WWFACI" Value="100" />
                <mashup:Parameter TargetKey="WWWHLO" Value="100" />
                <mashup:Parameter TargetKey="WWQTTP" Value="5" />
             </mashup:Event>
          </mashup:Events>
       </m3:ListPanel.Events>
       <m3:ListPanel.Bookmark>
          <m3:Bookmark Program="MMS200" Table="MITBAL" KeyNames="MBCONO,MBWHLO,MBITNO" FieldNames="WWFACI,WWHLO,WOPAVR,WWQTTP" />
       </m3:ListPanel.Bookmark>
    </m3:ListPanel>

 </Grid>

Regards
Ken Eric

2 thoughts on “Mashup/LES – Related search and changing view while searching.”

  1. Hi

    Thanx for a great post! But I have a problem/issue when creating search for items when I have to search both ITDS and FUDS. I dont know in which field my search-key is. So when searching ex. “door white 9×21” one of the search elements may be in FUDS, but the two first is in ITDS. Since all three is not in the same field, LES returns none.

    Is there a way to work around this?

    Like

Leave a comment