Mashup – Enable a button based on status and CurrentItemChanged

I’ll show you how to enabled a button on a current item changed event in a Mashup list. The scenario is as follows: You have a list of planned orders and you want to add a button to execute a related option but only if the order status has a specific value. I’ll show you how to set a property value in an event and how to execute a related option using a button. The real case scenario here would be planned work orders in MOS197 but for simplicity if you don’t use that module I’ll simulate the checks by using a much simpler program and one of my favorites, CRS610. The hard part is to reset the IsEnabled for the button to be false so that it does not keep its state as we select different rows in the list.

One trick is to use the Running event as described in a previous post. Another approach I’ll show you now is to use the same Event – twice. You might need to apply both these approaches if your list reloads, based on another selection, and you are very specific that the button should be disabled until the first row is selected. These tricks are quire useful and can be applied to S3 / Lawson mashups as well.

Let’s start by adding the list with a start-up event and the button that will run a related option.

<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="*" />
    <ColumnDefinition Width="Auto" />
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="Auto" />
  </Grid.RowDefinitions>
  <m3:ListPanel Name="listCustomers">
    <m3:ListPanel.Events>
      <mashup:Events>
        <mashup:Event SourceEventName="Startup">
          <mashup:Parameter TargetKey="OKCONO" />
          <mashup:Parameter TargetKey="OKCUNO" />
        </mashup:Event>
        <mashup:Event SourceName="listCustomers" SourceEventName="CurrentItemChanged" Target="{mashup:SetProperty ElementName=buttonOption, Path=IsEnabled}">
          <mashup:Event.Conditions>
            <mashup:Conditions>
              <mashup:Condition TargetKey="OKSTAT" SourceValue="20" Operator="Equal" />
            </mashup:Conditions>
          </mashup:Event.Conditions>

          <mashup:Parameter TargetKey="Value" Value="True" />
        </mashup:Event>
      </mashup:Events>
    </m3:ListPanel.Events>
    <m3:ListPanel.Bookmark>
      <m3:Bookmark Program="CRS610" Table="OCUSMA" KeyNames="OKCONO,OKCUNO" />
    </m3:ListPanel.Bookmark>
  </m3:ListPanel>
  
  <Button Name="buttonOption" Width="120" IsEnabled="false" Content="Related option" Grid.Column="1" VerticalAlignment="Center" Margin="10,10,10,0" />
</Grid>

List

This code almost work. We have the button and it is disabled and enabled only when status is 20, but as we select a new row the button remains enabled even if the condition is no longer met. One way to fix this is to add a new Event for CurrentItemChanged that always disables the button. It will be called before the conditional event so it will always re-set the IsEnabled to false.

<mashup:Event SourceName="listCustomers" SourceEventName="CurrentItemChanged" Target="{mashup:SetProperty ElementName=buttonOption, Path=IsEnabled}">>
   <mashup:Parameter TargetKey="Value" Value="False" />
</mashup:Event>

Note that you need to edit the XAML and move this line so that it comes after the conditional event. This approach is good to remember.

Mapping a related option to a button

Before writing this post I did not know how to map a button event to a list option. So I went into the Events for the button, added a click event and mapped it to a ListOption. But I did not get a suggestion for what TargetKey to use. I would have guessed for Option but there were no suggestion in the Parameters section after adding a new parameter. See below.

ListOption

I need to know more about the M3 ListPanel so I opened the SDK Documentation (unde Help menu in the Designer). I wanted to know more about the ListOption event so I searched for “ListOption”… and I found what I was looking for. The parameter name was described in the help it should be Option. Of course it would be nice if this information was in the tool but I think there is a limitation here that the editor does not support different target keys based on the name of the event.

SDKDoc

If you are using the Mashup controls and are not sure how to use them – don’t forget to check the code documentation.

Complete XAML below:

<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="*" />
    <ColumnDefinition Width="Auto" />
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="Auto" />
  </Grid.RowDefinitions>
  <m3:ListPanel Name="listCustomers">
    <m3:ListPanel.Events>
      <mashup:Events>
        <mashup:Event SourceEventName="Startup">
          <mashup:Parameter TargetKey="OKCONO" />
          <mashup:Parameter TargetKey="OKCUNO" />
        </mashup:Event>
        <mashup:Event SourceName="listCustomers" SourceEventName="CurrentItemChanged" Target="{mashup:SetProperty ElementName=buttonOption, Path=IsEnabled}">
          <mashup:Parameter TargetKey="Value" Value="False" />
        </mashup:Event>
        <mashup:Event SourceName="listCustomers" SourceEventName="CurrentItemChanged" Target="{mashup:SetProperty ElementName=buttonOption, Path=IsEnabled}">
          <mashup:Event.Conditions>
            <mashup:Conditions>
              <mashup:Condition TargetKey="OKSTAT" SourceValue="20" Operator="Equal" />
            </mashup:Conditions>
          </mashup:Event.Conditions>
          <mashup:Parameter TargetKey="Value" Value="True" />
        </mashup:Event>
      </mashup:Events>
    </m3:ListPanel.Events>
    <m3:ListPanel.Bookmark>
      <m3:Bookmark Program="CRS610" Table="OCUSMA" KeyNames="OKCONO,OKCUNO" />
    </m3:ListPanel.Bookmark>
  </m3:ListPanel>
  
  <Button Name="buttonOption" Width="120" IsEnabled="false" Content="Related option" Grid.Column="1" VerticalAlignment="Center" Margin="10,10,10,0">
    <Button.CommandParameter>
      <mashup:Events>
        <mashup:Event TargetName="listCustomers" SourceEventName="Click" TargetEventName="ListOption">
          <mashup:Parameter TargetKey="Option" Value="11" />
        </mashup:Event>
      </mashup:Events>
    </Button.CommandParameter>
  </Button>
</Grid>

14 thoughts on “Mashup – Enable a button based on status and CurrentItemChanged

  1. thibaudatwork

    Hi, I see the event uses TargetEventName=”ListOption” to start a Related Options. Is there an equivalent TargetEventName=”Key” to press Action keys? I need a button that presses F15 like we could do with MForms Automation it’s possible. Thanks. /Thibaud

    Reply
    1. norpe

      There is no event but you can use a button with a command. The example below shows a button that triggers the F5 function key. Note that the CommandTarget attribute must be set to the ListPanel unless the button is created within the ListPanel (using a ContentPresenter to show the list).

      <Button Command="{x:Static mforms:MFormsCommands.FunctionKey}" CommandParameter="F5" CommandTarget="{Binding ElementName=yourListPanel}" />
      
      Reply
      1. thibaudatwork

        Great! I confirm your code works for me; I have Smart Office 10.1.1.1.5. I just had to add the namespace xmlns:mforms=”clr-namespace:MForms;assembly=MForms”. Thanks. /Thibaud

  2. Mikael Malmberg

    Hi,

    this is the button, and tried to use your above example, but didn’t work.

     <xaml><Button Name="Refresh" Content="Refresh" Margin="2" Height="20" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" /></xaml>
    
    Reply
    1. karinpb Post author

      I don’t think all the code is there. You have a button – but no command is set on it.

      <Button Command="{x:Static mforms:MFormsCommands.FunctionKey}" CommandParameter="F5" CommandTarget="{Binding ElementName=yourListPanel}" />

      Reply
  3. Mikael

    Hi, I tried to add as per your example, didn’t work however. Got the following message:

    Provide value on “System.Windows.Markup.StaticsExtension” trhew an exception

     <xaml><Button Name="Refresh" Content="Refresh" Margin="2" Height="20" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" />
    			<Button Command="{x:Static mforms:MFormsCommands.FunctionKey}" CommandParameter="F5" CommandTarget="{Binding ElementName=LPPlannedMO}" /></xaml>
     
    Reply
    1. karinpb Post author

      Hi,
      That seems correct but perhaps you could share the entire xaml or a simplified one with the list and the button and nothing else. Then I could try it here in the Mashup Designer.

      Reply
  4. CAS

    Hi there, I was just wondering if it was also possible to trigger a button or event based on the outcome of an API call in a Mashup; for example I’m using a button to trigger an API call to update an M3 status and I would like to trigger another event or enable a button if the API is successful i.e. if no api error message is received. I have the solution working currently by calling a second API call directly after the first to return the new status and then enabling the button/event depending on the outcome of the status change. I was just wondering if it was possible to make the process simpler and eliminate the second API call to check the status and simply use the API dialog message instead. Thank you in advance (running Smart Office version 10.2 and M3 business engine 14.1)

    Reply
    1. karinpb Post author

      Hi, There is no good fit for what you would like to do. There is an UpdateComplete event but it will be raised even if there is an error. We have thought about adding more events to cover this and similar scenarios. I’ve added your description of the problem to the enhancement request. But for now I’m afraid there is no other way around it… unless a successful call returns some data that you could check in a binding. But it if is just OK / NOK then I’m not sure. If it returns data upon success then perhaps there is a way.

      Reply
  5. Mikael Malmberg

    Hi Karin, thank for all your support:

     <xaml><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="1*" />
    	</Grid.ColumnDefinitions>
    	<Grid.RowDefinitions>
    		<RowDefinition Height="1*" />
    		<RowDefinition Height="Auto" />
    		<RowDefinition Height="Auto" />
    		<RowDefinition Height="1*" />
    		<RowDefinition Height="Auto" />
    	</Grid.RowDefinitions>
    	<ui:StatusBar Name="StatusBar" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="1" Grid.RowSpan="1" />
    	<m3:ListPanel Name="LPPlannedMO" Header="Planned MO. Open" IsListHeaderVisible="True" Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0" Grid.RowSpan="1" InternalOptions="11">
    		<m3:ListPanel.Events>
    			<mashup:Events>
    				<mashup:Event TargetName="LPPlannedMO" SourceEventName="Startup">
    					<mashup:Parameter TargetKey="ROCONO" Type="Numeric" />
    					<mashup:Parameter TargetKey="ROPLPN" Type="String" />
    					<mashup:Parameter TargetKey="ROPLPS" Type="String" />
    				</mashup:Event>
    			</mashup:Events>
    		</m3:ListPanel.Events>
    		<m3:ListPanel.Bookmark>
    			<m3:Bookmark Program="PMS170" Table="MMOPLP" KeyNames="ROCONO,ROPLPN,ROPLPS" IncludeStartPanel="True" SortingOrder="1" View="HOG01-01" />
    		</m3:ListPanel.Bookmark>
    	</m3:ListPanel>
    	<StackPanel Orientation="Horizontal" Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="1" Grid.RowSpan="1" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0">
    		<Button Name="Change" Content="Change" Margin="2" Height="20" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left">
    			<Button.CommandParameter>
    				<mashup:Events>
    					<mashup:Event TargetName="LPPlannedMO" SourceEventName="Click" TargetEventName="ListOption">
    						<mashup:Parameter TargetKey="Option" Value="2" />
    					</mashup:Event>
    				</mashup:Events>
    			</Button.CommandParameter>
    		</Button>
    		<Button Name="Release" Margin="2" Height="20" Width="100" Content="Release" VerticalAlignment="Center" HorizontalAlignment="Left">
    			<Button.CommandParameter>
    				<mashup:Events>
    					<mashup:Event TargetName="LPPlannedMO" SourceEventName="Click" TargetEventName="ListOption">
    						<mashup:Parameter TargetKey="Option" Value="11" />
    					</mashup:Event>
    				</mashup:Events>
    			</Button.CommandParameter>
    		</Button>
    
    
    		<xaml><Button Name="Refresh" Content="Refresh" Margin="2" Height="20" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" />
               <Button Command="{x:Static mforms:MFormsCommands.FunctionKey}" CommandParameter="F5" CommandTarget="{Binding ElementName=LPPlannedMO}" /></xaml>
    		<Button Name="CheckCapacity" Content="Check Capacity" Margin="20,2,2,2" Height="20" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left">
    			<Button.CommandParameter>
    				<mashup:Events>
    					<mashup:Event TargetName="LPPlannedMO" SourceEventName="Click" TargetEventName="ListOption">
    						<mashup:Parameter TargetKey="Option" Value="16" />
    					</mashup:Event>
    				</mashup:Events>
    			</Button.CommandParameter>
    		</Button>
    		<Button Name="CheckMaterial" Content="Check Material" Margin="2" Height="20" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left">
    			<Button.CommandParameter>
    				<mashup:Events>
    					<mashup:Event TargetName="LPPlannedMO" SourceEventName="Click" TargetEventName="ListOption">
    						<mashup:Parameter TargetKey="Option" Value="12" />
    					</mashup:Event>
    				</mashup:Events>
    			</Button.CommandParameter>
    		</Button>
    	</StackPanel>
    	<GridSplitter Name="GS1" Style="{DynamicResource styleGridSplitterHorizontalMashup}" Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="2" Grid.RowSpan="1" />
    	<TabControl Name="TabControl" TabStripPlacement="Top" Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="3" Grid.RowSpan="1" Margin="5">
    		<TabItem Header="Material Plan">
    			<m3:ListPanel Name="LPMaterialPlan" IsListHeaderVisible="True">
    				<m3:ListPanel.Events>
    					<mashup:Events>
    						<mashup:Event SourceName="LPPlannedMO" TargetName="LPMaterialPlan" SourceEventName="CurrentItemChanged">
    							<mashup:Parameter TargetKey="MOCONO" SourceKey="ROCONO" Type="Numeric" />
    							<mashup:Parameter TargetKey="MOWHLO" SourceKey="ROWHLO" Type="String" />
    							<mashup:Parameter TargetKey="MOITNO" SourceKey="ROPRNO" Type="String" />
    							<mashup:Parameter SourceKey="ROPLPN" TargetKey="MORIDN" Type="String" />
    						</mashup:Event>
    					</mashup:Events>
    				</m3:ListPanel.Events>
    				<m3:ListPanel.Bookmark>
    					<m3:Bookmark Program="MMS080" Table="MITPLO" KeyNames="MOCONO,MOWHLO,MOITNO,MOPLDT,MOTIHM,MOORCA,MORIDN,MORIDL,MORIDX,MORIDI,MOSTAT" IncludeStartPanel="True" SortingOrder="1" />
    				</m3:ListPanel.Bookmark>
    			</m3:ListPanel>
    		</TabItem>
    		<TabItem Header="Product Structure">
    			<m3:ListPanel Name="LPProductStructure" IsListHeaderVisible="True">
    				<m3:ListPanel.Events>
    					<mashup:Events>
    						<mashup:Event SourceName="LPPlannedMO" TargetName="LPProductStructure" SourceEventName="CurrentItemChanged">
    							<mashup:Parameter SourceKey="ROCONO" Value="1" Type="Numeric" />
    							<mashup:Parameter TargetKey="WBFACI" SourceKey="ROFACI" Type="String" />
    							<mashup:Parameter TargetKey="WBPRNO" SourceKey="ROPRNO" Type="String" />
    							<mashup:Parameter TargetKey="WBSTRT" SourceKey="ROSTRT" Type="String" />
    						</mashup:Event>
    					</mashup:Events>
    				</m3:ListPanel.Events>
    				<m3:ListPanel.Bookmark>
    					<m3:Bookmark Program="PDS002" Table="MPDMAT" KeyNames="PMCONO,PMFACI,PMPRNO,PMSTRT,PMMSEQ,PMFDAT" FieldNames="WBFACI,WBPRNO,WBSTRT,WBSTRD" IncludeStartPanel="True" SortingOrder="1" />
    				</m3:ListPanel.Bookmark>
    			</m3:ListPanel>
    		</TabItem>
    	</TabControl>
    </Grid></xaml>
    
    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s