Refreshing the Sales Order snapshot from a sales order tab event

Recently I needed to find a way to cause the sales order snapshot to refresh when a server event triggered on a different Sales Order tab.  I was able to do so using the following code.

The snapshot is loaded onto the SalesOrderDetail quickform as a registered custom user control with the following syntax:

<%@ Register tagPrefix=”SalesLogix” tagName=”wbrSalesOrder” src=”~/SmartParts/SalesOrder/FXOrderSnapShot.ascx” %>
<SalesLogix:wbrSalesOrder id=”wbrSalesOrder” runat=”server” OnInit=”setwbrSalesOrderContext” ></SalesLogix:wbrSalesOrder>

The first thing we need to do is to get a reference to this custom user control from our other tab.  The best way of doing this is to loop through the controls on the form until we find the one we are looking for.  We can construct a recursive method to handle this function for us like so:

private static T FindControlRecursive<T>(Control Root, string Id) where T : Control
{

    if (Root.ID == Id && Root is T)
        return (T)Root;
    foreach (Control Ctl in Root.Controls)
    {
        var FoundCtl = FindControlRecursive<T>(Ctl, Id);
        if (FoundCtl != null)
            return FoundCtl;
    }
    return default(T);
}

Then to call the recursive method for the one item we want we can construct a method like so:

public static T GetControlReference<T>(System.Web.UI.Control form, string controlId) where T : Control
{
    return (T)FindControlRecursive<T>(form, controlId);
}

With these two methods we can then locate and instantiate a reference to the user control by calling something like this:

Sage.Platform.WebPortal.SmartParts.SmartPart sp =
GetControlReference<Sage.Platform.WebPortal.SmartParts.SmartPart>(this.Page,
“wbrSalesOrder”);

As you can see we are defining the control we are searching for is a SmartPart control type.  We are searching on the current page for the control and the control ID we are looking for is “wbrSalesOrder”, as defined on the SalesOrderDetails.ascx.  With our reference we are then able to work with the SmartPart methods available to rebind and refresh the snapshot.

Here is the completed code:

protected void RefreshSnapshot()
{
    Sage.Platform.WebPortal.SmartParts.SmartPart sp = GetControlReference<Sage.Platform.WebPortal.SmartParts.SmartPart>(this.Page, “wbrSalesOrder”);
    if (sp != null)
    {

        sp.InitSmartPart(ParentWorkItem, PageWorkItem.Services.Get<Sage.Platform.Application.UI.Web.IPageWorkItemLocator>());
        sp.DialogService = DialogService;
        Sage.Platform.WebPortal.SmartParts.EntityBoundSmartPart esp = sp as Sage.Platform.WebPortal.SmartParts.EntityBoundSmartPart;
        if (esp != null)
        {
            esp.InitEntityBoundSmartPart(PageWorkItem.Services.Get<Sage.Platform.Application.IEntityContextService>());
            esp.PanelRefresh.RefreshAll();
        }
    }
}

public static T GetControlReference<T>(System.Web.UI.Control form, string controlId) where T : Control
{
    return (T)FindControlRecursive<T>(form, controlId);
}

private static T FindControlRecursive<T>(Control Root, string Id) where T : Control
{

    if (Root.ID == Id && Root is T)
        return (T)Root;
    foreach (Control Ctl in Root.Controls)
    {
        var FoundCtl = FindControlRecursive<T>(Ctl, Id);
        if (FoundCtl != null)
            return FoundCtl;
    }
    return default(T);
}

Using this kind of logic allows you to not only work with a specific SmartPart user control.  You could also use the same procedure to manipulate any web control on the form, like a picklist, textbox, etc.

ABOUT THE AUTHOR

Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!