Determining the Page Mode at Runtime in SalesLogix Web

One of the keys to reusing a form for both inserting new records and displaying existing record detail is the ability to determine if the form is currently in insert mode or detail mode. There are several ways to determine this at runtime so you can take the necessary steps depeding on the current form mode.

Out of the box, there are three defined form types: Detail, Insert, & List

Some of the code we’ll use will differ whether you’re using a C# Snippet Action (where the code is added to the form itself) or a Code Snippet Action (where the code is added to a separate assembly and you’re passed an adapter object to access limited form properties).

From a C# Snippet Action

Use the following code to access the exposed EntityForm property of the form and determine the form mode.

if (EntityPage.IsInsertMode)
labelMode.Text = "Insert Mode";
else
labelMode.Text = "Not insert mode";


// or


if (EntityPage.ViewMode == Sage.Platform.Orm.Entities.EntityViewMode.Insert)
labelMode.Text = "Insert Mode";
else
labelMode.Text = "Not insert mode";

From a Code Snippet Action

For a Code Snippet Action, you’ll need to do things a little differently. In a Code Snippet Action you’re only passed an adapter, or a wrapper, for the form, not the form itself. So, the problem is that you cannot access the page’s EntityPage reference. You can still get to it however, you’ll just have a few extra steps to dig through. Luckily, the form adapter exposes the SmartPart via the NativeForm property.

// First get a reference to the underlying SmartPart itself
Sage.Platform.WebPortal.SmartParts.SmartPart smartpart = form.NativeForm as Sage.Platform.WebPortal.SmartParts.SmartPart;
// Now get the SmartPart's parent page and use it as an EntityPage
Sage.Platform.WebPortal.EntityPage page = smartpart.Page as Sage.Platform.WebPortal.EntityPage;
// Now you can proceed as normal...

if (page.IsInsertMode)
form.labelMode.Text = "Insert Mode";
else
form.labelMode.Text = "Not insert mode";


// or


if (page.ViewMode == Sage.Platform.Orm.Entities.EntityViewMode.Insert)
form.labelMode.Text = "Insert Mode";
else
form.labelMode.Text = "Not insert mode";

 
Checking the Entity’s ID Property

One last way you can use to check to see if the page is in Insert mode is to check the entity’s Id property. If it is null then you have a new entity, not yet persisted to the database.

if (myentity.Id == null)
// this is a new entity

The problem is that it is possible that this won’t infer the correct mode. That is telling you that the object hasn’t yet been persisted to the database, which might be enough, but you might want different behavior for new objects on the form vs the form being in insert mode itself. Just make sure that if you use this method to determine the page mode that you understand the differences so you know what you’re really checking.

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

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!