Showing results for 
Search instead for 
Do you mean 

Tech Tip: SalesLogix Web QuickForms – Shared logic and Utility methods- Part 2

by Employee on ‎01-21-2010 11:04 AM

Part 2 of a 3 part technical series discussing alternative techniques for coding shared logic and utility methods for use by Quickform and Control event handlers.

 

Part 1  of this series discussed techniques useful when utilizing the in-line C# Code Snippet Action Item (Obsolete) event handler option.


Part 2 - Technique when using Code Snippet Action item event handlers

 

If I have one or more form specific helper methods that I’d like to call from several controls event handlers on that form, where do I place the helper methods code since I can only write code for the controls events themselves?

While there is no explicit feature for adding form specific helper methods (hmm – feature request?), it turns out there is a technique staring us right in the face each time we write a code snippet event handler. In fact, thanks actually go to Mark Dykun for pointing out what was staring me right in the face.


Example: event handler for the Form OnLoad action

 

namespace Sage.BusinessRules.CodeSnippets

{

    public static partial class AccountDetailsEventHandlers

    {

        public static void OnLoad1Step( IAccountDetails form,  EventArgs args)

        {

              setMainPanelVisibility(form);

              setOptionalPanelvisibility(form);

        }

      

       // Any methods added here will be part of the class when compiled

       //

        private static void setMainPanelVisibility(IAccountDetails form)

       {

              // TODO: Complete helper method

       }

 

        private static void setOptionalPanelvisibility(IAccountDetails form)

       {

              // TODO: Complete helper method

       }

    }

}

 

 

Using Application Architect (AA), I generated an Event Handler for the Form OnLoad action event.

AA generates a partial class definition as well as the OnLoad1Step() method.

Notice that AA left the door open for us to sneak as many helper methods as we like just below the OnLoad1Step() method but still inside the partial class definition – thank you AA, we promise to close the door behind us!

OK – so how do I call those helper methods from a control’s Onchange event handler?

The Code Snippet based event handlers for each control on the form will also use the same partial class name and when all codesnippets are compiled together, all form methods – both the event handlers and helper methods will be accesible to each other.

Example: event handler for the Type picklist

 

namespace Sage.BusinessRules.CodeSnippets

{

    public static partial class AccountDetailsEventHandlers

    {

        public static void pklType_OnChange(IAccountDetails form, EventArgs args)

        {

            setMainPanelVisibility(form);

            setOptionalPanelvisibility(form);  

        }

    }

}

Standards and practices – While this technique will work with any Control event handler method, I recommend always using the Form OnLoad action for this technique so that you and other team members always know where to look for form helper methods.

 

Register Read Guidelines Request Partner or Employee Access

What's New in 8.1

Labels