Mashups, WebServices and Variable Substitution

So in my last post I was talking about my next wee experiment. Using a Mashup with a WebService and supplying the parameters for the WebService.

Initially I was thinking that this wouldn’t be an issue at all especially when there is this helpful post from the Infor team
http://lawsonsmartoffice.com/2012/03/09/mashups-bindings-markup-extension-methods-and-explained/#more-497

However, it’s never that simple 😦

My WebService goes out and retrieves the order lines from OOLINE and from the item master MITMAS. The WebService is a query created in LWS Designer:

SELECT oborno, obitno, mmfcu1, oborqt, round((oborqt / mmfcu1 * 100),2) as containerpercentage FROM m3edtprod.ooline LEFT OUTER JOIN m3edtprod.mitmas ON obitno = mmitno WHERE oborno = ?

It is used to calculate the percentage of a container that an order line occupies.

Attempting to run the variable substitution for the webservice like this

<mashup:DataParameter Key="GetFreeCaps1.OrderNumber" Value="{}{Query}" />

doesn’t work, using Fiddler (http://www.fiddler2.com/fiddler2/ a Web Debugger) I could see that the parameter being passed to the WebService as {Query}, rather than the value in the variable.

On the plus side, a very nice person at Infor provided a solution, don’t use the DataParameter or variable substitution at all πŸ™‚

What we do is we directly set the Order Number against the DataListPanel.

But first, let’s talk about the WebService Test as this will hopefully alleviate a question which will no doubt arise – where did I get the GetFreeCaps1 object from? :-).

In the later versions of Smart Office there is the WebService Test tool, you can run it by typing the following command tool://wstest

The Web Service Test Tool is a handy way for you to test a webservice and see what results are returned. I key in the URL of the webservice, hit load, select the operation and select the Test button. The really nice part is that we can see what M3 will call the name of the webservice object.

Back to it…

Our button will set the GetFreeCaps1 object associated with the DataListPanel:

   <Button Grid.Row="0" Name="btnSearch" Content="Search">
      <Button.CommandParameter>
         <mashup:Events>
            <mashup:Event TargetName="dlpDataPanel" SourceEventName="Click" TargetEventName="Get">
               <!--
               This is specifically where we set the the value in the WebService
               -->
               <mashup:Parameter TargetKey="GetFreeCaps1.OrderNumber" Value="{Binding ElementName=tbOrderNumber, Path=Text}" />
            </mashup:Event>
         </mashup:Events>
      </Button.CommandParameter>
   </Button>

So, the Mashup has an order number that we enter, then we hit the Search button which will populate the DataListPanel – the result is below:

Β 

And finally the 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">
	<Grid.Resources>
		<mashup:ShowMessage x:Key="ShowMessage" />
	</Grid.Resources>

	<Grid.ColumnDefinitions>
		<ColumnDefinition Width="1*" />
	</Grid.ColumnDefinitions>
	<Grid.RowDefinitions>
		<RowDefinition Height="40" />
		<RowDefinition Height="1*" />
		<RowDefinition Height="50" />
	</Grid.RowDefinitions>
	
	<!--
	We get our customer order number from this TextBox, this order number 
	will be used in the SQL selects where statement
	-->
	<TextBox Grid.Row="0" Name="tbOrderNumber" Text="0000090050" Width="100" Height="25" HorizontalAlignment="Left" />

	<!-- 
	This is the button that initiates the search
	It take the value from the TextBox above and set that value
	in the webservice
	-->
	<Button Grid.Row="0" Name="btnSearch" Content="Search">
		<Button.CommandParameter>
			<mashup:Events>
				<mashup:Event TargetName="dlpDataPanel" SourceEventName="Click" TargetEventName="Get">
					<!--
					This is specifically where we set the the value in the WebService
					-->
					<mashup:Parameter TargetKey="GetFreeCaps1.OrderNumber" Value="{Binding ElementName=tbOrderNumber, Path=Text}" />
				</mashup:Event>
			</mashup:Events>
		</Button.CommandParameter>
	</Button>

	<mashup:DataListPanel Name="dlpDataPanel" Grid.Row="1">
		<mashup:DataListPanel.DataService>
			<mashup:DataService Type="WS">
				<mashup:DataService.Operations>
					<mashup:DataOperation Name="Get">
						<!--
						The WebServoce
						-->
						<mashup:DataParameter Key="WS.Wsdl" Value="https://wlmx02:21006/lws-ws/LWSDeve/FreeCapsSQL?wsdl" />
						<mashup:DataParameter Key="WS.Address" Value="https://wlmx02:21006/lws-ws/LWSDeve/FreeCapsSQL" />
						<mashup:DataParameter Key="WS.Operation" Value="GetFreeCaps" />
						<mashup:DataParameter Key="WS.Contract" Value="FreeCapsSQL" />
						<!-- 
						Set the username and password for the webservice
						-->
						<mashup:DataParameter Key="lws.user" Value="LSO.USER" />
						<mashup:DataParameter Key="lws.password" Value="LSO.PASSWORD" />
						<!--
						Set the Company and Division
						-->
						<mashup:DataParameter Key="lws.company" Value="100" />
						<mashup:DataParameter Key="lws.division" Value="IFL" />						
						<!--
						Set where we get the credentials for logging in to the webservice
						-->
						<mashup:DataParameter Key="WS.CredentialSource" Value="Current" />
					</mashup:DataOperation>
				</mashup:DataService.Operations>
			</mashup:DataService>
		</mashup:DataListPanel.DataService>
		<!--
		The datagrid which will display the results
		-->
		<DataGrid Grid.Row="1" Margin="8" x:Name="datagrid" AutoGenerateColumns="True" ItemsSource="{Binding OrderLineCapCollection}" CanUserAddRows="False" CanUserDeleteRows="False" Style="{DynamicResource styleDataGrid}" />
	</mashup:DataListPanel>

	<ui:StatusBar Name="StatusBar" Grid.Row="2" Grid.Column="0" VerticalAlignment="Bottom" />
</Grid>


Β 

This entry was posted in M3 / MoveX, Mashups, Webservices. Bookmark the permalink.

5 Responses to Mashups, WebServices and Variable Substitution

  1. karinpb says:

    Nice! DataParameter doesn’t support variable substitution but if you pass in the value with the event you don’t need to add it as a DataParameter. We will always check the parameters from the event first. So if you require somekind of variable substitution you do that in the event and we will pick up the value from the event. So setting an event target key to GetFreeCaps1.OrderNumber should work as well.

    • potatoit says:

      Thanks Karin for the explanation. Is there a particular reason that the variable substitution isn’t supported with DataParameter? It would be a little more visible and intuitive if it was.
      Enhancement request time? πŸ™‚

      • karinpb says:

        You can achieve the same thing with events and in general variable substitution is only supported in Events. The issue here would be that perhaps your service want a {value} in which case you can never produce that input. That is probably why we decided not to implement it in the parameter directly.

  2. Heiko says:

    Hi Scott, some hints: It is not necessary to specify the user ID and password in the mashup. This can be set in the WebService Context with LCM. Therefore anyone can code mashups or even create and maintain SQL Web Services against a database without knowing the credentials for direct database access and can use a user profile in LSO which has not database access rights. I also recommend to fetch the company number from the user’s context values. Furthermore, in an earlier post on SmartOfficeDevelopers Karin explained how to have the WS Url dynamic by setting a profile value in the LSO settings, so a Mashup can be copied from TST or DEV to any other environment without any changes. Only the Web Service itself must be deployed once more.

    • potatoit says:

      Hi Heiko,

      thank you – I’ll definitely be looking at the WebService Context in LCM!

      And yes, good points about getting the company number / division and of-course the WebService URL from the LSO session – I was being a little too lazy πŸ˜‰

      Cheers,
      Scott

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 )

Facebook photo

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

Connecting to %s