Report writer function examples

Some examples are helpful when understanding this technique for accessing third-party data for reports. The first example describes how third-party contact history data from the sample integrating application can be made available for various customer reports. The second example describes how additional SOP line item data can be made available to SOP reports.

Example 1 - Contact history data

The following contact history data is to be available for use on various customer reports:

 

These items can all be returned as string values, so the rw_TableHeaderString() Report Writer function will be used to retrieve them. The following function trigger is registered:

l_result = Trigger_RegisterFunction(function rw_TableHeaderString, TRIGGER_AFTER_ORIGINAL, function GetContactHistoryData);
if l_result <> SY_NOERR then
	warning "Function trigger registration failed.";
end if;

The following is the trigger processing function that runs in response to this function trigger. This function will access the IG_Contact_History_MSTR table, retrieving the contact history information for the specified customer. The ID of the customer must be passed in through the sNumber parameter. The data item to be retrieved is specified by the iControl parameter.

Function name: GetContactHistoryData

 

function returns string sData;

in integer Dict_ID;
in string Report_Name;
in string sNumber;
in integer sType;
in integer iControl;

if Dict_ID = Runtime_GetCurrentProductID() then

	{Try to retrieve the customer's corresponding contact history record}
	'Customer Number' of table IG_Contact_History_MSTR = sNumber;
	get table IG_Contact_History_MSTR;
	if err() = OKAY then
		{Based on the control field, determine which string to return}
		case iControl
			in [1] {First Contact Date}
				sData = str('First Contact Date' of table IG_Contact_History_MSTR);
			in [2] {First Contact Salesperson}
				sData = 'Contact Salesperson ID' of table IG_Contact_History_MSTR;
			in [3] {Last Contact Date}
				sData = str('Last Contact Date' of table IG_Contact_History_MSTR);
			in [4] {Last Contact Salesperson}
				sData = 'Contact Salesperson ID 2' of table IG_Contact_History_MSTR;
		else
			sData = "[Not Found]";
		end case;
	end if;
end if;

The remaining work must be performed by the Report Writer user. A new calculated field must be created for the report that will access the contact history data. This calculated field will call the rw_TableHeaderString() Report Writer function, supplying the appropriate parameters to indicate which data to retrieve. For instance, to retrieve the “Last Contact Date” value, the following calculated expression would be used:

FUNCTION_SCRIPT( rw_TableHeaderString 3333 "RM Customer Report" RM_Customer_MSTR.Customer Number 0 3 )

Notice that the product ID for the sample integration (3333) is passed in, along with the report’s name, the ID of the customer for which information is being retrieved, and the control value 3 to indicate to the processing procedure that the last contact date is to be returned.

Once the calculated field is complete, it can be placed on the report. When the report is run, the trigger will be activated, and the trigger processing procedure will retrieve the appropriate contact history information.

Example 2 - SOP line item data

The following example describes how additional line item information can be made available for Sales Order Processing reports. An additional third-party table, SOP_Ship_Weight, contains shipping weight and vendor information for line items in a sales document. The primary key structure for the SOP_Ship_Weight table is the same as the SOP_LINE_WORK table in the Dynamics.dic dictionary.

These two items can all be returned as string values, and are line items, so the rw_TableLineString() Report Writer function will be used to retrieve them. A function trigger like the following function would need to be registered:

l_result = Trigger_RegisterFunction(function rw_TableLineString, TRIGGER_AFTER_ORIGINAL, function GetAdditionalSOPData);
if l_result <> SY_NOERR then
	warning "Function trigger registration failed.";
end if;

The following is the trigger processing function that runs in response to this function trigger.

Function name: GetAdditionalSOPData

 

function returns string sData;

in integer dict_id;
in string report_name;
in string sNumber;
in integer sType;
in currency cSequenceOne;
in currency cSequenceTwo;
in integer iControl;

{If this function is not for our product then quit}
if dict_id <> Runtime_GetCurrentProductID() then
	abort script;
end if;

{The SOP_Ship_Weight table is a parallel table to the SOP_LINE_WORK 
table and has the same primary key structure as that table: SOP Number, 
SOP Type, Component Sequence, Line Item Sequence. The report_name parameter
is not referenced here as we want to return the field data regardless of which
report it is used on.}

'SOP Number' of table SOP_Ship_Weight = sNumber;
'SOP Type' of table SOP_Ship_Weight = sType;
'Component Sequence' of table SOP_Ship_Weight = cSequenceOne;
'Line Item Sequence' of table SOP_Ship_Weight = cSequenceTwo;
get table SOP_Ship_Weight;

if err() = OKAY then
	{There are two additional pieces of data in this table: Item Shipping
	Weight and 'Vendor ID'. Integer values 1 and 2 will be used to identify
	the fields}
	case iControl
		in [1]
			{Item Shipping Weight is stored as an integer. Divide by
			100.0 to force decimal places and then convert to a string.}
			sData= str('Item Shipping Weight' of table SOP_Ship_Weight / 100.0);
		in [2]
			sData = 'Vendor ID' of table SOP_Ship_Weight;
	end case;
else
	sData = "[Not Found]";
end if;

The remaining work must be performed by the Report Writer user. For instance, the additional SOP data might be added to the SOP Blank Invoice Form. To identify a specific line in the sales document, the Component Sequence and Line Item Sequence values from the Sales Transaction Amounts Work table are used. These values are stored as long integers. The rw_TableLineString() function is expecting these values to be currencies, so two calculated fields must be created to convert the long integer values to currencies. For example, the calculated field expression for a new LineItemSequence calculated field would be:

SOP_LINE_WORK.Line Item Sequence

The calculated field would have the Currency return type.

An additional calculated field must be created for the report that will access the SOP shipping weight and vendor data. This calculated field will call the rw_TableLineString() Report Writer function, supplying the appropriate parameters to indicate which data to retrieve. For instance, to retrieve the shipping weight value, the following calculated expression would be used:

FUNCTION_SCRIPT( rw_TableLineString 3333   "SOP Blank Invoice"   SOP_LINE_WORK.SOP Number   SOP_LINE_WORK.SOP Type   ComponentSequence   LineItemSequence   1)

Notice that the product ID of the dictionary registering the function trigger (in this example 3333) is passed in, along with the report’s name, the document number and document type, the calculated fields for the component sequence and line item sequence, and the control value 1 indicating to the processing procedure that the shipping weight is to be returned.

Once the calculated field is complete, it can be placed on the report. When the report is run, the trigger will be activated, and the trigger processing procedure will retrieve the appropriate SOP line item information.


Documentation Feedback