Pass a Parameter into a Screen from the Command Bar in a LightSwitch Application


a Parameter into a Screen from the Command Bar in a LightSwitch Application step by step :

Step 1: Right click on the  OrderHeader table->Add Query.

image1.gif

Step 2: Change query name (OpenOrders)->Add filter (ShippedDate is null)->Save like the below image.

image2.gif

Step 3: Add screen->List and Details screen->Select OpenOrder from screen data->Check OrderHeader->Ok.

image3.gif

Step 4: Now edit query of  OpenOrders->Add filter->Select CustomerID as parameter->Add new ID->Parameter (CustomerID) and type is Integer->Save.

image4.gif

Step 5: Click OpenOrderListDetail screen->AddDataItem->Local Property->Type (Integer)->Name (CustomerID)->Ok->Check parameter box.

image5.gif

Step 6: Click CustomerID of OpenOrder->Select Parameter Binding as CustomerID.

image6.gif

Step 7: Click CustomerDetail screen->Screen CommandBar->Add->New button->Write name (OpenOrder)->Ok.

image7.gif

Step 8: Now Choose image->Import image->Ok.

image8.gif

Step 9: Right click on OpenOrder->Edit Execute Code->Write the below code.

image9.gif

using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
namespace LightSwitchApplication
{
    public partial class CustomerDetail
    {
        partial void Customer_Loaded(bool succeeded)
        {
            // Write your code here.
            this.SetDisplayNameFromEntity(this.Customer);
        }
        partial void Customer_Changed()
        {
            // Write your code here.
            this.SetDisplayNameFromEntity(this.Customer);
        }
        partial void CustomerDetail_Saved()
        {
            // Write your code here.
            this.SetDisplayNameFromEntity(this.Customer);
        }
        partial void OenOrders_Execute()
        {
            // Write your code here.
            this.Application.ShowOpenOrdersListDetail(this.Customer.Id)
        }
    }
}

Step 10: Run application->Open any customer->Click OpenOrder image->Design Screen->Customer property->Check show as a link->Save.

Step 11: Click OpenOrderListDetail screen->AddDataItem->Query->Select Customer_SinglrOrDefault->Ok.

image10.gif

Step 12 Click Id of Customer->Select Parameter Binding (CustomerID).

image11.gif

Step 13: Run application->Design screen->Add->AddNew>Move up first->Save.

image13.gif

Step 14: Click + sign in OpenOrder->Fill data->Save.

image14.gif