Examples of User Exits
Defining object variable
This example defines a variable that represents an ActiveX Automation Server:
object ob;Creating a default interface
This example creates an instance of the default interface of the Internet Explorer ActiveX Automation Server:
object ob;
ob = createobject("InternetExplorer.Application");
//Creates an instance of the default interface of an ActiveX Automation Server.Creating a specific interface
This example creates an instance of the Internet Explorer ActiveX Automation Server and requests a specific interface:
object ob;
ob = createobject("InternetExplorer.Application",
"{EAB22AC1-30C1-11CR-A7EB-000C05BAE0B}");
//Creates an instance of a specific interface of an ActiveX Automation Server.
//In this case, the IID is known (specified in braces).
//Note: The createobject command is more efficient if you use the IID
//instead of the interface name.This example creates an instance of the Internet Explorer ActiveX Automation Server, where the interface identifier of the desired interface is unknown, but the name of the interface is IWebBrowser:
object ob;
string[50] iid;
iid = getiid("InternetExplorer.Application", "IWebBrowser2");
ob = createobject("InternetExplorer.Application", iid);
//Creates an instance of a specific interface of an ActiveX Automation Server.
//In this case, the IID is not known, so the ProgID and name of the interface
//(IWebBrowser) are specified and Gentran:Server looks up the IID. The IID is
//loaded into the string variable "iid" and then that value is used to create
//the object.Deleting an object
An object must be deleted before the end of the map that uses it. It is more efficient to delete the object immediately when you no longer need it, although the Sterling Gentran:Server® translator deletes the object automatically at the end of the map. Also, if you assign one object to another one, both copies of the object must be deleted for that object to be properly unloaded.
This example deletes the object "ob" that was used in the previous examples:
deleteobject(ob);Getting a property value
This example obtains a property value from an ActiveX Automation Server:
object ob;
string[50] iid;
iid = getiid("InternetExplorer.Application", "IWebBrowser2");
ob = createobject("InternetExplorer.Application", iid);
IF ob.Visible = 1 THEN
BEGIN
//The property value is accessed.
END
//Test to see if the system displays the Internet Explorer.Setting a property value
This example sets a property value in an ActiveX Automation Server:
object ob;
string[50] iid;
iid = getiid("InternetExplorer.Application", "IWebBrowser2");
ob = createobject("InternetExplorer.Application", iid);
ob.Visible = 1;
//The property value is set. Display Internet Explorer on the desktop.Passing parameters to a method
To pass parameters
to a method, use the syntax objectname.methodname(parameters).
The Sterling Gentran:Server translator
automatically converts the extended rule data type of the property
to the ActiveX data type, whenever possible. If there is no directly
corresponding type in the extended rules, the conversion is performed
as well as possible by the operating system.
Sterling Gentran:Server relies on default data types. For example, Sterling Gentran:Server converts VT_CURRENCY (which is an unknown data type to the translator programming language) to a real or numeric data type. If the conversion cannot be performed, a type mismatch error is written to the Translator Report and the extended rule is immediately terminated.
This example navigates to a web page by passing the URL to the Navigate method of Internet Explorer:
object ob;
string[50] iid;
iid = getiid("InternetExplorer.Application", "IWebBrowser2");
ob = createobject("InternetExplorer.Application", iid);
ob.Navigate("www.sterlingcommerce.com");
//Navigates to the IBM web page by passing the URL to the Navigate
//method of Internet Explorer. Note: URL must be enclosed in quotation marks.Returning values in output parameters
To
return values in output parameters, use the syntax objectname.methodname(InputParameter,
OUT OutputParameter).
- Input and output parameters may occur anywhere in the parameter list.
- Output parameters must be preceded by the OUT keyword.
- When an extended rule variable is used as an output parameter, the ActiveX datatype must match exactly.
See Data types supported for a list of ActiveX data types and the analogous extended rule data type for each.
This example decrypts data in a field:
object ob;
ob = createobject("YourCompany.DecryptionUserExit");
ob.Decrypt("EncryptionKey", OUT #Field_Name);Testing successful object creation
This example tests the value of an object against zero to determine if it was correctly created:
object ob;
ob = createobject("YourCompany.DecryptionUserExit");
IF ob = 0 THEN
BEGIN
//Object not created properly; perform task X.
END
//Test to see if the object was created successful. If it was not
//created, perform the specified task.Obtaining another interface of an existing object
This example uses the IID of an object to obtain a different interface of an existing object (object1):
object ob, ob2;
ob = createobject("InternetExplorer.Application");
ob2 = queryobject(ob, "{EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B}");If the IID of the desired interface is unknown, use the getiid function to determine the correct IID and then use the queryobject function, as this example demonstrates:
object ob, ob2;
string[50] iid;
ob = createobject("InternetExplorer.Application");
iid = getiid("InternetExplorer.Application", "IWebBrowser2");
ob2 = queryobject(ob, iid);Accessing a database
This example uses a user exit to cross-reference a UPC code with a value in a database to return an SKU number. This example adds the user exit to an invoice (import) map (refer to the Sterling Gentran:Server tutorial folder, PET_810.MAP for an example). The user exit code is implemented by increments in the map, with each section added to the logical map component.
On Begin Extended Rule
Type the following code into the On Begin extended rule of the INPUT positional file:
//Declare the object
object ob;
//Create an instance of the C++ Active X Automation Server
ob = CreateObject("UpcSku.Application");
if ob = 0 then
begin
MessageBox("Create Object failed",0);
endINVDETAIL.UPCCODE Field Extended Rule
Type the following code into the UPCCODE field extended rule on the Input side of the map (INVDETAIL record):
string [100] msg;
msg = "UPC Code = ";
concat(msg,#UPCCODE,12);
//Call the automation server
#UPCCODE = ob.ResolveSKU(#UPCCODE);
concat(msg, ", SKU Code = ",13);
concat(msg,#UPCCODE,len(#UPCCODE));
//Display message box to user listing UPC code and SKU matches
MessageBox(msg,0);On End Extended Rule
Type the following code into the On End extended rule of the INPUT positional file:
//Delete the object
deleteobject(ob);