Q:

Displaying GI in tab on any screen

I want to display a GI on one of the tab in any screen. 
For example, there is a new custom GI for OrderMargin which I want to display on SO screen on a new tab that will show the Order Margin for a particular order only.
OrderMargin is simple GI with SOOrder, SOLine and InventoryItem table joins and few columns required columns with margin calculations.
Can anyone suggest?

A:

Let's say you've created a GI called SalesOrderMargin with 2 hidden parameters:

To embed this GI into the Sales Orders page, you should follow the steps below:

Declare new unbound field for SOOrder to return absolute URL for the SalesOrderMargin GI:
public class SOOrderExt : PXCacheExtension<SOOrder>
{
    public abstract class marginGiUrl : IBqlField { }
    [PXString]
    [PXUIField(Visible = false)]
    public string MarginGiUrl
    {
        get
        {
            if (string.IsNullOrEmpty(Base.OrderType) || 
                string.IsNullOrEmpty(Base.OrderNbr)) return string.Empty;

            string inqName = "SalesOrderMargin";
            var url = new StringBuilder(PXGenericInqGrph.INQUIRY_URL)
                .Append("?name=").Append(inqName)
                .Append("&SOOrderType=").Append(Base.OrderType);
                .Append("&SOOrderNbr=").Append(Base.OrderNbr);
                .Append("&hidePageTitle=true");
            return PX.Common.PXUrl.SiteUrlWithPath().TrimEnd('/') + 
                url.ToString().Remove(0, 1);
        }
    }
}

On the Sales Orders screen, add new tab with a PXSmartPanel container set up to render as an iframe:
<px:PXTabItem Text="Margins" >
    <Template>
        <px:PXSmartPanel runat="server" ID="panelMarginGI" RenderIFrame="True" 
            AutoSize-Enabled="true" SkinID="Frame" LoadOnDemand="true"/>
    </Template>
</px:PXTabItem>

Place input control for the custom SOOrder unbound field declared in step 1 somewhere in the Sales Orders' top level PXFormView container (input control will always be hidden from the users and is only required to assign source URL for the PXSmartPanel):
<px:PXFormView ID="form" runat="server" DataSourceID="ds" Width="100%" 
    DataMember="Document" Caption="Order Summary"...>
    <Template>
        ...
        <px:PXTextEdit ID="edMarginGiUrl" runat="server" DataField="MarginGiUrl" />
    </Template>
</px:PXFormView>

In SO301000.aspx insert JavaScript code to assign source URL for the PXSmartPanel: 
<script type="text/javascript" language="javascript">
    function commandResult(ds, context) {
        var commands = ["ReloadPage", "Save", "Cancel", "Insert", "First", "Previous", "Next", "Last"];
        if (commands.indexOf(context.command) >= 0) {
            var marginGiUrl = px_alls["edMarginGiUrl"];
            var smartpanel = px_alls["panelMarginGI"];
            if (marginGiUrl || smartpanel) {
                var url = marginGiUrl.getValue();
                smartpanel.setPageUrl(url);
                smartpanel.repaint();
            }
        }
    }
</script>

Subscribe to the CommandPerformed event of PXDataSource to invoke the commandResult JavaScript function:
<px:PXDataSource ID="ds" runat="server" Visible="True" Width="100%" TypeName="PX.Objects.SO.SOOrderEntry" PrimaryView="Document">
    <ClientEvents CommandPerformed="commandResult" />
    ...
</px:PXDataSource>

And this is how your SalesOrderMargin GI should appear on the Sales Orders screen:

