Login / Register  search  syndication

          Ryan Farley's Blog

Ryan Farley on .NET Development with a focus on CRM Development for SalesLogix

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.

What's This?
Bookmark and Share

About Ryan Farley

   Ryan Farley is the Director of Development for Customer FX Corporation and the creator of slxdeveloper.com.


Related Content
   Launching a report from a button in the SalesLogix web client
Starting in SalesLogix 7.5.1, Sage released an undocumented Reporting enhancement that allowed for intera
Posted on Mar 12, 2010 by Kris Halsrud to Kris Halsrud's Blog
 
   Hiding Opportunities in the SalesLogix web client
Occasionally we have clients who do not use the Opportunity components of the SalesLogix web client. 
Posted on Mar 10, 2010 by Kris Halsrud to Kris Halsrud's Blog
 
   Searching for Matching Records in the SalesLogix Web Client
In this short video the user will learn how to search for matching records while adding new records to th
Posted on Mar 10, 2010 by Dale Richter to Tech Talk
 
   Opening Several Records in the SalesLogix Web Client
This webinar will show the user how to open several records at one time. Often you would like to be able
Posted on Mar 10, 2010 by Dale Richter to SalesLogix Training
 
   Creating Ad-Hoc Groups in the SalesLogix Web Client
This webinar will show the user how to create Ad-Hoc Groups in the SalesLogix Web Client. This specific f
Posted on Mar 10, 2010 by Dale Richter to SalesLogix Training
 
Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2010 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register