In this section: |
How to: |
Your next step is to enable users to write the data that they type in this form to the data source. They do this by clicking a button that says Add at the bottom of the form. You add the button to your form and write the Maintain Data Language source code that inserts the data into the data source.
By default, App Studio Maintain Data names forms and controls with their type and a unique number. If you are planning to refer to a form or control in other places in the procedure, giving it a more descriptive name is recommended.
How to: |
Now that you have created a button that the user will click, you must create the code to run when the user clicks the button.
You put this code in a function. A function is a series of commands in a procedure grouped together as a unit of control. A function accomplishes a task, such as calculating values, extracting data from a data source to place in a data source stack, or writing information to a data source.
App Studio Maintain Data opens the source code for your function in the Maintain Data Editor.
Underlying many of the graphical elements of App Studio Maintain Data is Maintain Data language source code. The Maintain Data Text Editor enables you to create, view, and edit the source code for procedures, procedure components, and other types of files required by your Maintain Data applications. The Maintain Data Text Editor tab opens when you create a new function or edit an existing one. It contains two groups, Find and Position. The Maintain Data Text Editor tab is shown in the following image.
All App Studio Maintain Data procedures start with the keyword MAINTAIN (which must be in uppercase) and end with the keyword END (also in uppercase), as shown in the following image. When you create a procedure, App Studio Maintain Data includes these two keywords automatically.
|
MAINTAIN FILE fannames $$Declarations Case Top Infer fannames.CUSTOMER.SSN into AddFanStack; Winform Show Form1; EndCase Case AddFan EndCase END |
Note: The text in your window may wrap differently.
FILE fannames tells App Studio Maintain Data the data sources this procedure is going to access. In the list of components, there is a Data Sources folder with a fannames data source below it.
Data source names (up to 15) follow the MAINTAIN FILE command and are separated by the word AND.
Following this line is a comment line beginning with $$. You can tell that this is a comment since green (the default) is the color for comments. This comment line is automatically generated when you create a procedure.
This particular comment, $$Declarations, is generated automatically by App Studio Maintain Data when you created the procedure. If you create any new variables using the Request & Data Sources panel, App Studio Maintain Data places the source code after this comment.
Case Top begins the definition of the Top function. This definition takes up several lines and ends with the keyword EndCase. The first statement, which begins with Infer, defines the AddFanStack data source stack.
The next line of the Top function, Winform Show Form1; is the code that displays Form1 at run time. This code was generated automatically when you created the procedure.
Finally, the Case AddFan and EndCase define an additional function in this procedure.
The Find group contains options that enable you to find or replace text.
The commands in the Find group are:
Finds the specified text. You can also press Ctrl+F to activate the Find dialog box.
Finds the next instance of the specified text.
Finds the previous instance of the specified text.
Replaces the specified text with different text.
Selects all of the text in the procedure.
You can use the options on the Find dialog box to indicate how to search for information.
The options on the Find dialog box are:
Provides a text box where you can specify the text that you want to find.
Select this option to match the uppercase or lowercase value, as specified in the Find what field.
Select this option to match the whole word only.
Allows you to find the next instance of your search term.
You use the options on the Replace dialog box to indicate how to use the find feature to find and replace information.
The options on the Replace dialog box are:
Provides a text box where you can specify the text that you want to find.
Provides a text box where you can specify the text that is going to replace the text for which you are searching.
Select this option to match the uppercase or lowercase value, as specified in the Find what field.
Select this option to match the whole word only.
Allows you to find the next instance of your search term.
Replaces the search information that you specified in the Find What field with the text or other information that you indicated in the Replace With field.
The Position group allows you to place your cursor at the desired line and allows you to turn off line numbers.
The commands in the Position group are:
Displays the current line your cursor is on. You can type a different line number into the text box to place your cursor on that line.
When selected, displays line numbers. This option is selected by default.
The Maintain Language Wizard opens. The Maintain Language Wizard helps you build Maintain Data language source code without typing the syntax yourself.
The first Language Wizard window asks you to specify, in general, what kind of task you want to accomplish.
Now that you have specified the general task you want to perform, the Language Wizard narrows the task further. Notice that after each task, there is a word in parentheses. This is the name of the Maintain Data language command that executes that task. Additionally, notice the box at the bottom of the window contains the Maintain Data language code being generated by the Language Wizard. As you move through the Language Wizard, you see more code.
Now that you have specified which command to use, the Language Wizard asks you to supply the parameters for that command. In this case, you must tell it which data source is being updated and from where.
You first specify which data source is being updated.
Note: The Available fields list contains the data sources that you are using in this procedure, not the list of data sources in the folder.
Notice that, as with stacks, all the other fields in the CUSTOMER segment are also copied, as shown in the following image. This is because the Maintain Data language assumes that if you are adding new data source records to a data source, you want to write information into all the fields in a segment. For more information, see Stacks and Implied Columns.
Notice that the Maintain Data language box at the bottom now reads as follows:
Include fannames.CUSTOMER.SSN;
Your final step is to indicate where this data is being written from, which in this case, is AddFanStack.
Notice that the Maintain Data language box at the bottom now reads as follows:
For all include fannames.CUSTOMER.SSN from AddFanStack;
App Studio Maintain Data places the source code that the Language Wizard generated in between the Case AddFan and EndCase lines.
How to: |
Now that you have included the data from AddFanStack into the fannames data source, it is a good idea to clear the data from AddFanStack. Use the Language Wizard to write this code.
For all include fannames.CUSTOMER.SSN from AddFanStack;
but before
EndCase
The Language Wizard asks you to select one or more stacks to clear.
Stack clear AddFanStack;
How to: |
Now that you have written the code that inserts user data into the data source, you need to designate that when the user clicks the Add button, this function is performed. You do this using the Tasks & Animations panel.
An event is something that a user performs, such as clicking a button or moving to a field. Events are done as tasks with Ajax calls. The target type and request is mntname.case.
This will make the Add button call that case (function).
Note: You need to have Start.Connect in the load task or this will not work.