#GPPT Beginner’s Guide to Adding Custom Fields – Creating the RW function


David Meego - Click for blog homepageWelcome to the fifth article in the series of articles that explain in detail the steps to add a user defined custom field to a window using Modifier, Report Writer and GP Power Tools to add the business logic.

The series should be read in order starting with the introduction article:

In this article we will use GP Power Tools to create a custom Report Writer (RW) function which will allow our custom URL field to be easily added to reports in the Report Writer.

For the business example we are working through, we need to add an internet URL field to the Item Maintenance window which can be opened in an internet browser.

The process to do this can be broken down into 6 Steps:

  1. Modifying the Window; Use Modifier to add the URL field to the Item Maintenance window with a hyperlinked prompt.
  2. Saving the Data; The data will be stored in the DUOS (Dynamic User Object Store) SY90000 table and business logic will be added to handle saving the URL field.
  3. Using the Data; Make the hyperlink open the URL in a browser window.
  4. Creating the Report Writer Function; Use Power Tools to create a Report Writer Function to allow the data to be pulled into reports.
  5. Modifying the Report; Use Report Writer to add a calculated field to call the Report Writer Function.
  6. Publishing the Project; Change settings to make the project available to all users.

Follow the steps below to complete Step 4: Creating the Report Writer Function. We will use a Runtime Execute script with a specific purpose to create a RW function which can be used from a calculated field in the Report Writer. (Click on images to see full sized versions and full scripts are listed at the end of the article).

  1. On the Project Setup window, from the toolbar select Add >> Runtime Execute Setup. Set the Script ID to ITEM URL GET and Script Name to Get Web URL Link field for Report Writer.
  2. As this script is going to be a custom Report Writer function we can select an appropriate Custom Script Purpose. Even though the list of rw_* functions looks like they have specific purposes, you can use any of them as long as the parameters passed in and out meet your requirements.  We need to be able to pass in a string for Item Number and need a string value returned, so we will use rw_TableHeaderString().
  3. We will use the string Number parameter (MBS_Number) for the Item Number and place the data we want returned into the string MBS_TableHeaderString variable. Place your cursor below the { Add your code below here } line and use the Helper button to add the Get a DUOS Property help function.
  4. Change “ID” placeholder to MBS_Number and the “Object” and “Property” placeholders to “Item and “URL” respectively. Add the line MBS_TableHeaderString = MBS_Property; after the call to place the retrieved value into the variable to be returned. Finally remove any double blank lines to tidy up the formatting.
  5. Click Save and the script should be displayed on the Project Setup window.

Note: There is a limitation in Dexterity’s Report Writer where a string Calculated field is truncated to 80 characters. It is possible to add extra code to use the substring() function to return any additional characters. Or, if you want to split into lines without breaking a word in half, you can use the RW_ParseString() RW function (which in turn uses the Field_ParseText() function) to split a longer string into lines of X characters. You can use the same report writer function to return different data based on the parameters passed in.

Optional: We can enhance the script to handle returning more than one custom field and to return the extra data longer than 80 characters if it exists. We could use the MBS_Type variable to specify the line to return and the MBS_Control variable to specify which custom field to return with a value of 1 representing the URL field (split by 80 characters) and 2 representing the URL field (parsed to 80 character lines). To make it backwards compatible with the non-enhanced version of the script we will allow a value of 0 to still work as before. See the enhanced script below.

Below is the script for the custom RW Function:

ITEM URL GET Runtime Execute Script

local string MBS_TableHeaderString;
local string MBS_Number;
local integer MBS_Type;
local integer MBS_Control;
local string MBS_String;
local string MBS_ObjectID;
local string MBS_Property;

call with name "MBS_Param_Get" in dictionary 5261, "Number", MBS_Number;
call with name "MBS_Param_Get" in dictionary 5261, "Type", MBS_String;
MBS_Type = integer(value(MBS_String));
call with name "MBS_Param_Get" in dictionary 5261, "Control", MBS_String;
MBS_Control = integer(value(MBS_String));
MBS_TableHeaderString = "";

{ Add your code below here }

MBS_ObjectID = MBS_Number;
call with name "MBS_DUOS_Get" in dictionary 5261, "Item", MBS_ObjectID, "URL", MBS_Property;
MBS_TableHeaderString = MBS_Property;

{ Add your code above here }

call with name "MBS_Param_Set" in dictionary 5261, "TableHeaderString", MBS_TableHeaderString;

ITEM URL GET Runtime Execute Script (Enhanced)

local string MBS_TableHeaderString;
local string MBS_Number;
local integer MBS_Type;
local integer MBS_Control;
local string MBS_String;
local string MBS_ObjectID;
local string MBS_Property;

call with name "MBS_Param_Get" in dictionary 5261, "Number", MBS_Number;
call with name "MBS_Param_Get" in dictionary 5261, "Type", MBS_String;
MBS_Type = integer(value(MBS_String));
call with name "MBS_Param_Get" in dictionary 5261, "Control", MBS_String;
MBS_Control = integer(value(MBS_String));
MBS_TableHeaderString = "";

{ Add your code below here }

case MBS_Control
	in [0] { URL }
		MBS_ObjectID = MBS_Number;
		call with name "MBS_DUOS_Get" in dictionary 5261, "Item", MBS_ObjectID, "URL", MBS_Property;
		MBS_TableHeaderString = MBS_Property; { Will be truncated to 80 characters in Report Writer}
		
	in [1] { URL Split to 80 characters }
		MBS_ObjectID = MBS_Number;
		call with name "MBS_DUOS_Get" in dictionary 5261, "Item", MBS_ObjectID, "URL", MBS_Property;
		MBS_TableHeaderString = substring(MBS_Property, 1 + 80 * (integer(value(MBS_Number)) {Line} - 1), 80 {Characters});
		
	in [2] { URL Parsed to 80 character lines }
		MBS_ObjectID = MBS_Number;
		call with name "MBS_DUOS_Get" in dictionary 5261, "Item", MBS_ObjectID, "URL", MBS_Property;
		MBS_TableHeaderString = RW_ParseString(MBS_Property, 80 {Characters}, integer(value(MBS_Number)) {Line});
		
	else
end case;

{ Add your code above here }

call with name "MBS_Param_Set" in dictionary 5261, "TableHeaderString", MBS_TableHeaderString;

In the next article we will use the Report Writer to modify the Detailed Item List Report so that it shows the custom URL field.

Hope you find this series useful.

David

This article was originally posted on http://www.winthropdc.com/blog.

One thought on “#GPPT Beginner’s Guide to Adding Custom Fields – Creating the RW function

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.