The Text Parameter Passed to 4D Methods Called via URLs
By ACI US Technical Support
Technical Note 97-13
Technical Notes for 97-05-May 1997
Introduction
As described in the 4th Dimension Language Reference manual, you can bind a 4D method to an HTML object by specifying /4DMETHOD/Name_of_your_method as the URL for the link. For details, see the Language Reference manual section Web Services, Your First Time (Part II).
There is an undocumented point of information regarding this feature — 4th Dimension sends a text parameter to any 4D method called via a URL. Regarding this text parameter:
Although you do not use this parameter, you must explicitly declare it with the line C_TEXT($1), otherwise runtime errors will occur while using the Web to access a database that runs in compiled mode.
This parameter returns the extra data placed at the end of the URL, and can be used as a placeholder for passing values from the HTML environment to the 4D environment.
Runtime Errors in Compiled Mode
Let's consider the following example. You just received your 4D Pro or 4D Desktop package. You compile a database to be served on the Web. You execute a method bound to an HTML object using a link and you obtain the following screen on your Web browser:
This runtime error is related to the missing declaration of the text $1 parameter in the 4D method that is called when you click on the HTML link referring to that method. As the context of the execution is the current HTML page, the error refers to the "line 0" of the method that has actually sent the page to the Web browser.
Following the example from the Language Reference manual, you can quickly fix the problem by explicitly declaring the text $1 parameter within the M_ADD_RECORDS and M_LIST_RECORDS methods:
` M_ADD_RECORDS project method C_TEXT($1) ` This parameter MUST be declared explicitely Repeat ADD RECORD([Customers]) Until(OK=0) ` M_LIST_RECORDS project method C_TEXT($1) ` This parameter MUST be declared explicitely ALL RECORDS([Customers]) MODIFY SELECTION([Customers])
Note: See the original source of these methods in the Technical Note Web Services, Your First Time (Part I).
After these changes have been made, the compiled runtime errors no longer occur.
Working with the URL Extra Data
The text $1 parameter passed to the 4D method returns the extra data appended to the URL.
Again following the example in the Language Reference manual, the change (shown below) is made to the URL of the link that refers to the M_ADD_RECORDS method:
Note: The screen shot depicts the change as made using Claris Home Page on MacOS.
The data added to the URL is therefore the string "/extraData". After this change has been made, you can use the Debugger window, on the 4D side, to quickly check that the $1 parameter actually returns the string "/extraData":
By using conventions and algorithms similar to those described in the section On Web Connection Database Method of the Language Reference manual, you therefore have the means to exchange additional data between the HTML and the 4D environments when a 4D method is called by an HTML link.
How to Dynamically Set the URL Extra Data
If you create and write your own HTML files "on the fly" (using, for example, Create document and SEND PACKET), you simply write the URLs accordingly to your needs.
If you work with existing HTML files, you can use JavaScript to dynamically set the link propertie(s) of your object(s).
Summary
4th Dimension sends a text parameter to any 4D method called via a URL. This parameter returns the extra data placed at the end of the URL. You must explicitly declare this parameter with the line C_TEXT($1), otherwise runtime errors will occur while running the database in compiled mode. You can use this parameter to exchange additional data between the HTML and 4D environments when a 4D method is called by an HTML link.
See Also
C_TEXT, On Web Connection Database Method, Web Services, Your First Time (Part I), Web Services, Your First Time (Part II).