Você está na página 1de 42

Developing for Sage SalesLogix LAN v7.

5 Lesson 1

Lesson 1
Basic Customizations
This lesson provides a chance to practice basic customization skills learned in the
Introduction to Developing for Sage SalesLogix LAN v7.5 course. You will also
complete a series of exercises to enhance the original project (DevIntro) to track
courses and enrollments.
You will learn how to:
z Install the DevIntro bundle, and review the customizations to become familiar
with the SalesLogix Architect.
z Add customizations to the DevIntro project

Exercises in this Lesson

Install and Review the DevIntro Bundle..........................................................13


Modify the Course Enrollment Data Grid ........................................................17
Create a Data Form to Add Enrollments from the Courses Main View...........20

© 2008 Sage Software, Inc. Certified Student Curriculum 11


Basic Customizations Sage SalesLogix v7.5

DevIntro Project Install and Review


In the Introduction to Developing for Sage SalesLogix course, you created a
customization project (DevIntro) to allow users to track courses and enrollments for
their contacts in the SalesLogix Client. Your trainer saved the bundle for this
project—including all of its plugins and actions—to the ClassFiles folder on your
desktop. You will need this bundle to complete the exercises in this lesson.
Before you start the next exercise, you should understand the following topics:
z Bundling a project (covered in the Introduction course)
z Releasing a plugin (covered in the Introduction course)
z Installing a bundle (new)

Installing a Bundle
Bundles are saved in files with the extension .sxb, and work with any database type.
You can install a bundle using the Bundle Manager in the SalesLogix Administrator
(Nav Bar > Bundles). The Bundle Manager controls the installation and removal
of bundles in your SalesLogix database.
SalesLogix installs bundle components in the order listed on the Scripts tab in
Bundle properties. All plugins contained in SalesLogix bundles are identified by the
version number when they were last modified. Version numbers are represented by
a four-decimal float field (####.####), which allows differentiation between major,
minor, patch, and hot fix releases. For example, plugins that were modified for
SalesLogix version 6.2, Service Pack 1 display as version 6.2.1.
With this version system, any existing plugin will not be removed or modified when
you apply a bundle containing the same plugin, unless the plugins have a duplicate
name, family, type, company, and company version.

NOTE: In the classroom, your trainer has already created a connection to a Development
database, which is a back-up of the SalesLogix Evaluation database. You will use
Development in all connection strings later in this course. Your trainer has also modified
the appropriate logging paths for the SYNCSERVER, SYNCSERVICEFILE, and
BRANCHOPTIONS tables when setting up the development environment.

12 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 1

Exercise 1.1: Install and Review the DevIntro Bundle


In the Introduction to Developing for Sage SalesLogix LAN v7.5 course, you
started a new project (DevIntro) to allow SalesLogix users to track courses
and enrollments for their SalesLogix contacts. In this exercise you will install and
review this project.

Detailed Steps
This exercise is designed to give you enough criteria to complete the exercise on
your own. If you need to reference step-by-step instructions, refer to the page shown
below. Try to complete as much of the exercise using only the quick steps below
before consulting the step-by-step instructions.
Exercise 1.1 on page 149

Quick Steps
After reviewing the following criteria, start the exercise.
1. Install the bundle used in the Introduction to Developing course.
z Log on to the Administrator. Create a DEVELOPMENT database
connection and data link.
z Use the DevIntro.sxb file, which is located in the ClassFiles folder on your
desktop.
z Do not update any releases.
2. Review the plugins installed.
3. Review the table schema used in the project.
Ready, Set, Go!

© 2008 Sage Software, Inc. Certified Student Curriculum 13


Basic Customizations Sage SalesLogix v7.5

Quick QA
After completing the exercise, log on to the SalesLogix Client as admin. Use the
following check list to verify you completed all the required steps.

† The Course Enrollment data grid appears as a tab on the Contact Detail view.

† When you right-click in the data grid and click Add Enrollment, the Insert New
Enrollments form appears, which allows you to add and edit enrollments.

† The Insert New Enrollments form opens a lookup when you click the Search
button next to the Course Name box. The lookup allows you to search for all
courses by course name.

14 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 1

† A Courses button appears on the Sales Nav Bar Group.

† When you click the Courses button, a Course main view appears. The Course
Detail view includes a Course Detail form and a Contact Enrollments data grid.

© 2008 Sage Software, Inc. Certified Student Curriculum 15


Basic Customizations Sage SalesLogix v7.5

DevIntro Project Concept Review


Before you start the exercises, you should understand the following topics:
z Changing column properties
z Using lookups (covered in the Introduction course)
z Using data forms (covered in the Introduction course)

Changing Column Properties


The Columns property for the DataGrid control allows you to create or modify
columns in the data grid. (SalesLogix recommends creating your SQL statements
through the Query Builder first, and then using the DataGrid Columns property to
enter column settings.)
In the Introduction to Developing for Sage SalesLogix course, you already created
columns through the SQL property, so you can now use the Columns property to
edit aspects of the appearance and behavior.

Each column has standard properties. In the next exercise you will use the following
properties:
z Read Only
z Disable Editor
z Format and Format/String
In addition to standard properties, each column type has specific properties.
Column types include Check, Combo, and more. In the next exercise you will use
the Check column type.

NOTE: In most cases, settings entered through the DataGrid Columns property overwrite
formatting settings entered through the Query Builder. Exceptions include Visibility, Read
Only, and Width.

16 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 1

Exercise 1.2: Modify the Course Enrollment Data Grid


The Course Enrollment data grid (C_EnrollDataGrid) tracks the courses for which
a particular contact has enrolled. It contains data from two different tables:
C_Course and C_Enrollment. In this exercise you will change the column
properties so that users can only edit columns that update the C_Enrollment table.
You will make all other fields from the C_Course table read only.

Detailed Steps
This exercise is designed to give you enough criteria to complete the exercise on
your own. If you need to reference step-by-step instructions, refer to the page shown
below. Try to complete as much of the exercise using only the quick steps below
before consulting the step-by-step instructions.
Exercise 1.2 on page 158

Quick Steps
After reviewing the following criteria, start the exercise.
1. Create a new Architect project named DevAdvanced, and add the
C_EnrollDataGrid form from the DevIntro bundle to the new project.
2. Apply the specified properties and formatting to the columns in the data grid.

Column Read Only Disable Editor Format Format String Column Type

Course
Selected Selected None Standard
Name

Price Selected Selected Currency Standard

Paid Cleared Cleared Boolean Check

StartDate Selected Selected DateTime mmm-dd Standard

EndDate Selected Selected DateTime mmm-dd Standard

Ready, Set, Go!

© 2008 Sage Software, Inc. Certified Student Curriculum 17


Basic Customizations Sage SalesLogix v7.5

Quick QA
After completing the exercise, log on to the SalesLogix Client as admin. Use the
following check list to verify you completed all the required steps.

† You can edit only the Paid column directly from within the Course Enrollment
data grid.

† The data grid should have appropriate formatting for each column (refer to the
following figure).

18 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 1

Working Ahead
If you finished this exercise early, complete the following Quick Steps to enhance
the project. These steps are not required to continue with the exercises.
1. Add the C_ContactEnrollDataGrid form to the DevAdvanced project.
2. Apply the specified properties and formatting to the columns in the data grid.

Column Read Only Disable Editor Format Column Type

FullName Selected Selected None Standard

HomePhone Cleared Cleared ftPhone Standard

Email Cleared Cleared None Standard

Mailing City/State/
Selected Selected None Standard
Zip

Paid Cleared Cleared ftBoolean Check

3. Increase the Width property for the Email and Mailing columns.
When finished, the data grid should have appropriate formatting for each
column (refer to the following figure):

© 2008 Sage Software, Inc. Certified Student Curriculum 19


Basic Customizations Sage SalesLogix v7.5

Exercise 1.3: Create a Data Form to Add Enrollments


from the Courses Main View
The Contact Enrollment form lists each contact enrolled for the selected course.
In this exercise, you will create a data form so users can add new enrollments from
a right-click menu on the Contact Enrollment form.

Detailed Steps
This exercise is designed to give you enough criteria to complete the exercise on
your own. If you need to reference step-by-step instructions, refer to the page shown
below. Try to complete as much of the exercise using only the quick steps below
before consulting the step-by-step instructions.
Exercise 1.3 on page 163

Quick Steps
After reviewing the following criteria, start the exercise.
1. Use an existing lookup to retrieve the ContactID and Contact Last Name for use
on the form.
2. Create a new data form (C_ADDEDITContactEnrollment) to allow users to
add/edit an enrollment. The form should have the following controls:

Control Name Properties

z ReadOnly: selected
EditBox edtCourseName z Enabled: cleared
z Color: clBtnFace

z HideButtonIfReadOnly: cleared
z Lookup: (CONTACT:Lastname)
LookupEdit lkpContactName
z LookupID: (C_ENROLLMENT:CONTACTID)
z Required: selected

CheckBox chkPaid

3. Modify the existing C_ContactEnrollmentDataGrid form to launch the form


from a right-click menu. The form should allow adds, edits, and deletes.
Ready, Set, Go!

20 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 1

Quick QA
After completing the exercise, log on to the SalesLogix Client as admin. Use the
following check list to verify you completed all the required steps.

† You can right-click in the Course Enrollment data grid


(C_ContactEnrollDataGrid) and view a list of menu options: Add Enrollment, Edit
Enrollment, Delete.

† When you right-click in the data grid and choose Add Enrollment, the Insert
Contact Enrollments Information window (C_ADDEDITContactEnrollment)
appears.

† When you click Search next to the Contact Name box, the lookup by contact last
name appears.

© 2008 Sage Software, Inc. Certified Student Curriculum 21


Basic Customizations Sage SalesLogix v7.5

Working Ahead
If you finished this exercise early, complete the following Quick Steps to enhance
the project. These steps are not required to continue with the exercises.

TIP: Add the C_CoursesMV to your DevAdvanced project.

1. Remove the More Tabs option from the Courses main view.
2. Set the Contact Enrollment tab as the default.
3. Change the Course main view to display the CourseName in the Lookup Bar
(Title Bar).
When finished the main view should look similar to the following figure:

4. Remove the warning message to users about displaying a large data set.

TIP: Use the Architect Help to look for the “Set General Client Options” topic.

22 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 1

Check Your Knowledge

1. What properties would you set on a data grid column to make the column Read
Only and so the user cannot click into the cell?
a. ReadOnly selected
b. Disable Editor selected
c. Cursor set to arrow
d. Enabled cleared

2. How do you set a specific custom format for a column?


a. Format String
b. Format selected
c. You cannot set your own formatting.

3. What properties must be set on a data grid in order to allow an Add/Edit form?
a. ____________________________________
b. ____________________________________

4. Which of the following options is a valid column type?


a. ID
b. Picture Blob
c. Standard
d. Integer

5. How do you remove the warning “This group is potentially large. Are you sure
you want to open it?” from displaying?
______________________________________________________________
______________________________________________________________

© 2008 Sage Software, Inc. Certified Student Curriculum 23


Basic Customizations Sage SalesLogix v7.5

24 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Lesson 2
Basic Programming
This lesson provides a chance to practice basic programming skills. You will
complete a series of exercises to create a customization project that uses scripts to
enhance functionality.
You will learn how to:
z Customize a manage form
z Create scripts in SalesLogix
z Use data validation
z Implement object-oriented-programming concepts in your customizations

Exercises in this Lesson

Create a Menu Item to Launch a New Manage Form.....................................28


Execute a SQL Statement to Return the Number of Contacts........................30
Execute a SQL Statement to Update a Field .................................................32
Use the Debugger ..........................................................................................37
Use Error Handling ........................................................................................38
Create a Modal Manage Form to Capture Values for Course Fields .............40
Use VBScript to Validate Data .......................................................................44
Save Form Data to the Database ..................................................................48

© 2008 Sage Software, Inc. Certified Student Curriculum 25


Basic Programming Sage SalesLogix v7.5

Manage Forms Customizations


Before you start the next exercises, you should understand the following topics:
z Using manage forms
z Creating menu bars
z Using the Application object
z Executing SQL statements

Using Manage Forms


A manage form enables you to create a form that is not tied to a specific table.
These forms can be called from other forms and are generally used for entering new
information.

Creating Menu Bars


The Menus Editor allows you to customize menus and menu items in the
SalesLogix Client. The menu that ships with SalesLogix is referred to as the
Standard Menu. To ensure that your menu changes merge with the default menus
included with SalesLogix, you must modify the Standard Menu.

26 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Using the Application Object


SalesLogix has a built-in COM object called the Application object. There are many
useful properties and methods that are used within the SalesLogix development
environment. You can use the Application object from within your SalesLogix
code, and you can also use the Application object from within an external .NET
application.

FOR MORE INFORMATION: Refer to the “Reference” lesson in the Introduction to


Developing for Sage SalesLogix workbook. Refer to page 10 to download this workbook.

In the next exercise you will need to familiarize yourself with the following
functions from the Application.BasicFunctions object:
z CurrentAccountID: Returns the current account ID.
z CurrentAccountName: Returns the current account name.
In addition, you should also familiarize yourself with the ADO Connection object,
which allows a connection to your datasource and allows you to execute SQL
against your database. In the next exercise you will use the following method:
Application.GetNewConnection: Built-in SalesLogix function that returns a valid
connection based on your datalink.
Finally, you should also familiarize yourself with the ADO Recordset object,
which is returned from the ADO command object execute method or the ADO
connection object execute method.

Executing SQL Statements


Including SQL statements in your sub procedures is a common task. When you add
SQL, remember the following tips:
z Always enclose the statement between quotation marks:
strSQL = “Statement goes here.”
z Enclose all literal values in single quotation marks.
“SELECT * FROM Table WHERE Column = ‘Literal value goes here.’”
z Use Query Analyzer or other tool to test the statement before adding it to your
script.

© 2008 Sage Software, Inc. Certified Student Curriculum 27


Basic Programming Sage SalesLogix v7.5

Exercise 2.1: Create a Menu Item to Launch a New


Manage Form
For this exercise, you will create a menu item to launch a form. This form should
contain a button that displays a “Hello World” message box when clicked. You will
also use the Application object to return the current Account Name and Account ID
in an edit box on the manage form.

Detailed Steps
This exercise is designed to give you enough criteria to complete the exercise on
your own. If you need to reference step-by-step instructions, refer to the page shown
below. Try to complete as much of the exercise using only the quick steps below
before consulting the detailed steps.
Exercise 2.1 on page 170

Quick Steps
After reviewing the following criteria, start the exercise.
1. Create a manage form. Add a button to the form (Click Me) that uses an
OnClick event.
2. Add a new label (Account Name and ID:) and edit box to the manage form.
3. Use the Application.BasicFunctions object to retrieve the account name and ID,
and display the data in the same edit box.

TIP: Concatenate both variables separated by a colon.

4. Save the form as C_HelloWorldForm in the Personal family.


5. Add a new menu item to launch the new form. The menu should display as
Dev Course > Hello World from the standard SalesLogix Client Menu Bar.
6. Save the menu as C_IntroMenu in the Personal family.

Ready, Set, Go!

28 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Quick QA
After completing the exercise, log on to the SalesLogix Client as admin. Use the
following check list to verify you completed all the required steps.

† The Dev Course menu is merged with the Standard Menu Bar and includes a Hello
World menu item

NOTE: Because the form is a manage form, it is not tied to an existing main view table;
therefore, it is not automatically displayed in a main view’s More Tabs area.

† The form displays an empty edit box when launched from the Dev Course >
Hello World menu.

† When you click the Click Me button, the Hello World message box appears and the
current account name and ID appear in the edit box.

© 2008 Sage Software, Inc. Certified Student Curriculum 29


Basic Programming Sage SalesLogix v7.5

Exercise 2.2: Execute a SQL Statement to Return the


Number of Contacts
For this exercise, you will create a SQL statement to return the number of contacts
for the current account.

Detailed Steps
This exercise is designed to give you enough criteria to complete the exercise on
your own. If you need to reference step-by-step instructions, refer to the page shown
below. Try to complete as much of the exercise using only the quick steps below
before consulting the detailed steps.
Exercise 2.2 on page 177

Quick Steps
After reviewing the following criteria, start the exercise.
1. Create a new function called GetContactCount.

TIP: You can copy and paste from the Snippet1.txt file in the ClassFiles folder to
get started.

2. Create a connection using the Application object.


3. Create a SQL SELECT statement to return the number of contacts for the
current account.
4. Create a recordset to store the results of the SQL statement, and then display the
results on the Hello World message box.

TIP: Make sure you set the objects to nothing and close the connection object when
finished.

Ready, Set, Go!

30 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Quick QA
After completing the exercise, log on to the SalesLogix Client as admin. Use the
following check list to verify you completed all the required steps.

TIP: Make sure you are viewing the Account main view before testing the customization.

† The form launches from the Dev Course > Hello World menu.

† When you click the Click Me button, the Hello World message box appears with
the record count text below the “Hello World” text.

© 2008 Sage Software, Inc. Certified Student Curriculum 31


Basic Programming Sage SalesLogix v7.5

Exercise 2.3: Execute a SQL Statement to Update a Field


For this exercise, you will create a new memo box on the form to record the
business description. You will also create a new button to update the database with
any changes to the description.

Detailed Steps
This exercise is designed to give you enough criteria to complete the exercise on
your own. If you need to reference step-by-step instructions, refer to the page shown
below. Try to complete as much of the exercise using only the quick steps below
before consulting the detailed steps.
Exercise 2.3 on page 180

Quick Steps
After reviewing the following criteria, start the exercise.
1. Add a new label (Description of Business:) and memo box to the form.
2. Add a button to the form (Save) that uses an OnClick event. The sub procedure
should include a SQL UPDATE statement and the Connection object
EXECUTE method to update the business description.

TIP: Make sure you use the BusinessDescription field; not the Description field.

TIP: You can copy and paste from the Snippet2.txt file in the ClassFiles folder to
get started.

3. Display the number of records updated on a message box when a user clicks the
Save button.
Ready, Set, Go!

32 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Quick QA
After completing the exercise, log on to the SalesLogix Client as admin. Use the
following check list to verify you completed all the required steps.

TIP: Make sure you are viewing the Account main view before testing the customization.

† The form launches from the Dev Course > Hello World menu.

† After you click Click Me, update the Business Description, and then click Save, a
message box appears that indicates the number of records affected.

† After you close the form, navigate to the next record in the list, and then navigate
back to the original record, the Business Description in the Detail area
automatically updates.

© 2008 Sage Software, Inc. Certified Student Curriculum 33


Basic Programming Sage SalesLogix v7.5

Working Ahead
If you finished this exercise early, complete the following Quick Steps to enhance
the project. These steps are not required to continue with the exercises.
1. Use the Application object to display the Business Description data from the
Account Detail area in the memo box on the C_HelloWorldForm open event.
2. After you click Save, refresh the Account Detail form.
3. Update only if the Business Description box (on the manage form) is not blank.
4. Add hot-key functionality to all the buttons on the form.
When finished, the manage form and the Account Details form should update
from either location (if conditions are satisfied), and both buttons should be
accessible through hot keys.

5. How could you use the SLX Database Support script to manage the connection
and execution of the UPDATE statement?
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________

34 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Debug and Error Handling Tools


Before you start the next exercise, you should understand the following topics:
z Using the Visual Studio debugger
z Error handling within VB

Using the Visual Studio Debugger


Debugging your code is essential to writing bug-free code. Within the SalesLogix
environment, you can use the Visual Studio debug tools.

You can launch the Visual Studio in two ways:


z Put a Stop command in your SalesLogix VBScript.
z Change the Debug option to On Error within the SalesLogix Client Tools >
Options, Other tab.

TIP: Do not set the debug mode to Always because SalesLogix launches debugging for
every line of code, whether it contains an error or not.

© 2008 Sage Software, Inc. Certified Student Curriculum 35


Basic Programming Sage SalesLogix v7.5

Within the SalesLogix Debugging mode in Visual Studio, you can choose from
several options under the Debug > Windows menu:
z Watch: Allows you to watch a certain variable or set a stop command when a
variable reaches a certain value.
z Immediate: Allows you to ask a question or set a variable to a certain value.
z Locals: Allows you to see what variables are currently in scope.

Error Handling with VB


VBScript does not have all the built-in error handling functionality that VB or other
programming languages have. Therefore, you must handle errors similar to the way
in which you might handle errors in a classic ASP application. Using On Error
Resume Next in your code, you can isolate the area in the code that throws the error
in order to take corrective action.
On Error Resume Next tests for an err.number after each line of code that has a high
probability of throwing an error, such as:
z Setting objects
z Retrieving data from the database
z Using external components
z Mathematical functions

TIP: Use built-in SalesLogix Error Handling functions to help you out!

36 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Exercise 2.4: Use the Debugger


For this exercise, you will use the Visual Studio debug tools within the SalesLogix
development environment. These tools help you find bugs in your code, change
code on the fly, and understand the flow of your program.

Detailed Steps
This exercise is designed to walk you through the debugging features in Visual
Studio. Using your C_HelloWorldForm form, you will conduct a series of steps that
help you learn how to:
z Step into and step over code
z Use the Immediate Window
z Add and modifying code to the Watch list
z Use the err.description property
Refer to the following page to locate detailed steps.
Exercise 2.4 on page 184

Quick Steps
There are no quick steps for this exercise.

© 2008 Sage Software, Inc. Certified Student Curriculum 37


Basic Programming Sage SalesLogix v7.5

Exercise 2.5: Use Error Handling


For this exercise, you will use the Visual Studio debugger functionality to help you
handle errors.

Detailed Steps
This exercise is designed to walk you through the debugging features in Visual
Studio. Using your C_HelloWorldForm form, you will conduct a series of steps that
help you learn how to:
z Use On Error Resume Next
z Use the ErrorCheck procedure within the SLX Error Support script
z Display custom error messages by using the err.number property
Refer to the following page to locate detailed steps.
Exercise 2.5 on page 191

Quick Steps
There are no quick steps for this exercise.

38 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Scripts
Before you start the next exercise, you should understand the following topics:
z Using manage forms (covered in Project 3)
z Using menus (covered in Project 3)
z Using combo boxes with script

Using Combo Boxes with Script


The ComboBox control gives the user a predefined list of items to choose from. It
differs from the PickList control because it is not populated from a pick list field in
the database. A combo box combines an edit box with a scrollable list. Use the
ComboBox control to allow users to either type text in the edit box or to select an
item from a list.

When users enter data into the combo box, either by typing text or selecting an item
from the list, the value of the Text property changes. The list of items displayed in
a combo box is stored in the Items property.

Use the Items property to load the items into the control. The user can select a value
from the combo box and other procedures can use that value.

© 2008 Sage Software, Inc. Certified Student Curriculum 39


Basic Programming Sage SalesLogix v7.5

Exercise 2.6: Create a Modal Manage Form to Capture


Values for Course Fields
For this exercise, you will add a new menu item to insert a new course. The Insert
Course form should script to populate some of the form values to comply with
business rules.

Detailed Steps
This exercise is designed to give you enough criteria to complete the exercise on
your own. If you need to reference step-by-step instructions, refer to the page shown
below. Try to complete as much of the exercise using only the quick steps below
before consulting the detailed steps.
Exercise 2.6 on page 197

Quick Steps
After reviewing the following criteria, start the exercise.
1. Append a new Course menu item (C_ADDCourseMenu) to the standard
SalesLogix Client Insert menu after the Campaign menu item to launch a new
Add a New Course manage form (C_ADDCourse).
2. Populate the Price combo box through VBScript in the form Create event.
Format the values as currency and range from $300-$2100 with increments of
$300 using a For Next loop.
3. Populate the No of Places combo box (6 and 12) through VBScript in the form
Create event. Do not use a loop. Default to 12 using ItemIndex in VBScript.
4. The controls on the form should function the same way as the controls on the
Course Details form (C_CourseDetail). You may want to copy and paste these
controls on the new form.
Additionally, you should modify the default manage form buttons:

Control Properties

z Caption: OK
Button z Name: btnOK
z Functionality: Doesn’t do anything yet. You will add the
functionality to save the data in a later exercise

z Caption: Cancel
Button z Name: btnCancel
z Functionality: This button should close the form. This
functionality works without the use of code.

40 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Quick QA
After completing the exercise, log on to the SalesLogix Client as admin. Use the
following check list to verify you completed all the required steps.

† The form launches from the Insert > Course menu.

† The Add a New Course form (C_ADDCourse) has functioning controls for Course
Name, Start Date, End Date, Instructor, Price, No of Places, and Room.

† The No of Places combo box has values of 6 and 12, with default set to 12.

† The Price combo box has values of $300, $600, $900, $1200, $1500, $1800, and
$2100 (formatted as currency).

© 2008 Sage Software, Inc. Certified Student Curriculum 41


Basic Programming Sage SalesLogix v7.5

Data Validation
Before you start the next exercise, you should understand the following topics:
z Using ModalResult
z Using AXFormCloseQuery
z Using VBScript built-in date functions
z Using Include Script and SLX_Util

Using ModalResult
All buttons have a property called ModalResult. The default value of this property
is set to ‘mrNone’. If you set the ModalResult to any other value, you can check to
see which button the user clicked when different form events are triggered. You
check to see the value by referencing the variable ModalResult in your code.
Some examples of ModalResult values include mrCancel, mrOK, mrYes, mrNo,
mrNone, and more.

Using AXFormCloseQuery
This function is called when the onCloseQuery form event is fired. You can
reference and set the value AXFormCloseQuery from within the
AXFormCloseQuery function. The function returns TRUE or FALSE.

Value Description

The default for this property is set to True, which means the form
True
will close if you do not set or use this property.

False If set to False, the form does not close.

42 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Using VBScript Built-In Date Functions


The built-in date functions in VBScript include the following:

Function Description

Adds a time interval to any date.


DateAdd z Parameters: (interval, number, validdate)
z Returns: date

Returns a designated part of a date.


DatePart z Parameters: (interval, validdate)
z Returns: specified part of the given date.

Valid interval values include the following: "d" (day), "m" (month), "yyyy" (year),
"q" (quarter), "ww" (week), "h" (hour), "n"(minute), "w" (weekday), and more.

Using Include Script and SLX_Util


Use Include Script to include VBScript into your current script.

All available script and VBScript plugins are available for you to use. In the System
family, the SLX_Util plugin provides several functions that you can use when
validating data on a form. Some of the functions include the following:
z ShowMessage(msg)
z ShowError(msg)
z ShowQuestion(msg)*
z ShowWarning(msg)
z ShowWarningQuestion(msg)*

NOTE: *This function returns true or false

© 2008 Sage Software, Inc. Certified Student Curriculum 43


Basic Programming Sage SalesLogix v7.5

Exercise 2.7: Use VBScript to Validate Data


For this exercise, you will use several VBScript functions to manipulate and
validate data on a form before the user can save course information.

Detailed Steps
This exercise is designed to give you enough criteria to complete the exercise on
your own. If you need to reference step-by-step instructions, refer to the page shown
below. Try to complete as much of the exercise using only the quick steps below
before consulting the detailed steps.
Exercise 2.7 on page 203

Quick Steps
After reviewing the following criteria, start the exercise.
1. If the user selects a Start Date, manipulate the End Date using the OnChange
event of startdate populates with a date two days from the selected Start Date.
2. Create a function called IsWeekend(). Use the datepart function to determine if
the date is a weekend.
z Parameter: Date
z Returns: T/F
3. Create a function called ValidateCourse() to run when the OnCloseQuery
event fires.
z Parameter: none
z Returns: T/F
z Displays: A message box with validation errors using SLX_Util script and
an appropriate function.
z Business Rules:
z Start Date and End Date cannot be on a weekend.
z End Date cannot be less than the Start Date.
z Start Date cannot be greater than the End Date.
z All fields are required.

TIP: You can copy and paste from the Snippet3.txt and Snippet4.txt files in the
ClassFiles folder to get started.

4. Close the form without validating any data if the user clicks Cancel. Use the
AXFormCloseQuery with the ModalResult value to determine if the user
clicked Cancel or OK.

44 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Quick QA
After completing the exercise, log on to the SalesLogix Client as admin. Use the
following check list to verify you completed all the required steps.

† Verify the Start Date and End Date fields only allow entries as outlined in the
business rules.

† Verify all other fields pass validation of required entry.

† If a field does not pass validation, a message box appears, which tells you what
fields do not pass validation, and the form does not close.

© 2008 Sage Software, Inc. Certified Student Curriculum 45


Basic Programming Sage SalesLogix v7.5

Working Ahead
If you finished this exercise early, complete the following Quick Steps to add
additional validation to the form. These steps are not required to continue with the
exercises.
1. The Price should be greater than 0 and in an increment of $300.

TIP: Use the MOD function.

2. The Number of Places should be greater than 0 and 12 or less. Also, the
available seats should be in increments of 6 (either 6 or 12).

TIP: You can use one of several ways to do this, but can also use the MOD function.

3. Make the text in the message box more user-friendly:


a. Include a message indicating that the Start Date and End Date cannot be
on a weekend.
b. Include a message indicating that the Price must be in multiples of $300.
c. Include a message indicating that the Number of Places must be in
multiples of 6.
4. If a user selects a Start Date that will cause the End Date to fall on a weekend
(due to the dateadd functionality), automatically change the End Date to the
next available weekday.

TIP: You can use a combination of the IsWeekend function and the DateAdd function.

5. Verify no Start Date or End Date spans more than 6 days total. The longest
class can be 5 days.
6. If the user entered an invalid value, change the color to vbRed.

46 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Using Command Object and Parameterized Queries


Using the Command object provides another way to execute SQL statements.
Benefits of using the Command object include the following:
z You can use parameters when defining your query.
z You don’t need to guess at data types.
z There are no problems with concatenation and string quotes
z Parameterized queries execute faster than non-parameterized queries, are more
straight forward, and less prone to errors.

FOR MORE INFORMATION: Refer to the “Reference” lesson in the Introduction to


Developing for Sage SalesLogix workbook. Refer to page 10 to download this workbook.

Using a VBScript Built-In Constant


A constant in VBScript is a named item that retains a constant value throughout the
execution of the script. Constants can be used anywhere in your code in place of
actual values. A constant can be a string or numeric literal, another constant, or any
combination that includes arithmetic or logical operators except Is and
exponentiation. For example:
Const A = "MyString"

The CONST, once declared does not change.

NOTE: In this case, you will use a constant variable because a name is easier to remember
and you will use it to store several SQL constants in one location so the SQL is easier to
find in case of a change.

Using a DataCommand Class and a SQLStatement Script


to Save Data
In the next exercise, you will create a new DataCommand class and a
SQLStatement script within the Architect. These plugins will be used throughout
the remaining exercises to create a connection to the database and pass a SQL
statement to update or insert data into the database. You should understand the
following notes about inserting data into the database using these plugins.
z Application.BasicFunctions.GetIDfor(“tablename”) returns a new record ID.
z CreateUser, CreateDate, ModifyUser, and ModifyDate fields are automatically
updated by the SLX provider so you do not need to pass them in the SQL.
z If you use inline SQL instead, you must use
Application.BasicFunctions.DateToISO(myDateVariable).

© 2008 Sage Software, Inc. Certified Student Curriculum 47


Basic Programming Sage SalesLogix v7.5

Exercise 2.8: Save Form Data to the Database


For this exercise, you will create a SQL statement script and a DataCommand class
to save data to the database from the Add a New Course form.

Detailed Steps
This exercise is designed to give you enough criteria to complete the exercise on
your own. If you need to reference step-by-step instructions, refer to the page shown
below. Try to complete as much of the exercise using only the quick steps below
before consulting the detailed steps.
Exercise 2.8 on page 208

Quick Steps
After reviewing the following criteria, start the exercise.
1. Change the AXCloseQuery function to call a Save sub that uses the
DataCommand class.
2. Create a VBScript plugin to contain parameterized SQL statements. Also create
a SQL INSERT statement using ? for parameters. Make this a Const.
3. Create a VBScript plugin to contain a DataCommand class.

TIP: You can copy and paste from the Snippet5.txt file in the ClassFiles folder.

This class should have the following methods, events, and properties:

Type Name Description

Read only property set during the Command object


Property RecordsAffected
EXECUTE statement

z Parameters: SQL Statement


z Returns: Recordset
Method Execute z Functionality: Executes the passed in SQL
statement and sets the value of variable
RecordsAffected

z Parameters: ParamType, ParamValue


z Returns: n/a
Method AddParam z Functionality: Creates an adds a parameter to
the Command object. If ParamType is advarchar,
then you must set the size ADOCmd.Size = len().

Sets up the Command object and sets the object’s


Event Class_Initialize
connection information.

Event Class_Terminate Sets the command object to nothing.

48 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Quick QA
After completing the exercise, log on to the SalesLogix Client as admin. Use the
following check list to verify you completed all the required steps.

† Open the Add a New Course form from the Insert > Course menu. Fill in all the
required information. When you click OK, a message box should appear to indicate
whether or not the save was successful.

† The new course should be recorded to the database. Open SQL Enterprise Manager
to view the new record in the back-end.

© 2008 Sage Software, Inc. Certified Student Curriculum 49


Basic Programming Sage SalesLogix v7.5

Working Ahead
If you finished this exercise early, complete the following Quick Steps to add
additional functionality to the DataCommand class. These steps are not required to
continue with the exercises.
1. The size of the parameter is determined through code. Change the AddParam
method and plan for additional data types. Add additional IF/THEN logic that
plans for the adLongVarBinary with size 8, an empty value, which would be a
NULL of size 2, and other types of strings.

TIP: Research on the Internet to find out which data types need a size and what sizes they
need to be.

2. Remove the SQL parameter passed into the EXECUTE method and create a
SQLText property. If you set the SQLText property BEFORE you do the
AddParam method, you will load the default parameter types and sizes. This
makes it unnecessary to specify the type and size properties with AddParam.
Why does this happen?
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
What are the benefits to using this approach?
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
What are the cons of using this approach?
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________

50 Certified Student Curriculum © 2008 Sage Software, Inc.


Developing for Sage SalesLogix LAN v7.5 Lesson 2

Check Your Knowledge

1. What Application.BasicFunctions object property returns the current contactid?


a. CurrentContactID
b. ContactID
c. GetCurrentContactID
d. You cannot retrieve the current contactid using Application object

2. How do you append to the existing menuing system?


a. You cannot append to an existing menu.
b. Create a new plugin, use the Standard Menu, and add the new menu item.
c. Open the Plugin Manager, choose Standard Menu, and add the new
menu item.

3. What SQL statement returns a count of the contact table in a one row recordset?
a. Select * as count from Contact
b. Select count(*) from contact
c. Select count(ID) from contact
d. You cannot return the count of a table.

4. What is the correct syntax for returning a recordset using the Execute method
of the Connection object?
_____________________________________________________________

5. To add a value to a combo box through script, what combo box collection
should you use?
a. Item
b. Items
c. Add
d. Display

© 2008 Sage Software, Inc. Certified Student Curriculum 51


Basic Programming Sage SalesLogix v7.5

6. You can set the AXFormCloseQuery to True/False in the OnCloseQuery event


of a form.
a. True
b. False

7. Using a const allows you to change the variable at runtime.


a. True
b. False

8. What benefits are possible when you use the Command object to execute your
SQL statements? (Circle all that apply.)
a. You do not have to guess at the data types.
b. You do not have to use concatenation and string quotes
c. They replace stored procedures
d. They execute faster
e. You can use parameters
f. There are no benefits; I'm going to continue to use inline SQL!

52 Certified Student Curriculum © 2008 Sage Software, Inc.

Você também pode gostar