Custom Action Methods

When designing a custom action, note that it must consist of the following four methods:

GetInputParameters

Initializes the input parameters. An input parameter for the name is taken from the buffer and the global variable is assigned its value. Refer to the following code sample to examine the GetInputParameters method.

GetInputParameters (VAR Buffer : Record "Scribe Parameters Buffer")

// get 'QuoteNoToConvert' parameter


Buffer.GET'QuoteNoToConvert';
DocumentNo := Buffer.Value;

ExecuteCustomAction

Uses the initialized variables from the previous step, calls C/AL code. The following code sample displays the ExecuteCustomAction method.

ExecuteCustomAction ()

// get sales header to post

SalesHeader.GET(SalesHeader."Document Type"::Quote, DocumentNo);

// convert sales quote to order

SalesQuoteToOrder.SetHideValidationDialog(TRUE);

SalesQuoteToOrder.RUN(SalesHeader);

The following table displays the local variables defined for this procedure.

Name DataType Subtype Length
SalesHeader Record Sales Header  

SetOutputParameters

Inserts the name and the value of the output parameter to the buffer. Refer to the following code sample to examine the SetOutputParameters method.

Note: The GetOutputParameters and SetOutputParameters methods must be designed to read data from and write data to the Scribe Parameters Buffer table.

SetOutputParameters(VAR Buffer : Record "Scribe Parameters Buffer")

// set output parameters

SalesQuoteToOrder.GetSalesOrderHeader(ConvertedSalesHeader);

Buffer.INIT;

Buffer.Name := 'ConvertedOrderNo';

Buffer."No." := 2;

Buffer.Value := ConvertedSalesHeader."No.";

Buffer.INSERT;

The following table provides local variables defined for this procedure.

Name DataType Subtype Length
ConvertedSalesHeader Record Sales Header  

If designing the GetInputParameters and SetOutputParameters methods, there is a need to convert values from text to any Microsoft Dynamics NAV data type or from any Dynamics NAV data type to text. For this purpose, you can use the predefined type convert methods placed in the Scribe Type Conventions codeunit. The following are some of these type convert methods: TextToInteger, TextToBigInteger, TextToBoolean, TextToDecimal.

You can view the complete list of these functions under View > C/AL Symbol Menu when in the design mode of the codeunit.

ResetToDefaults

Fills the Scribe Custom Actions and Scribe Action Parameters tables with data. It checks the Scribe Parameters Buffer table for the record identified by the "ResetToDefaults" name, and if finds it, deletes all data that corresponds to the identification of the current custom action, creates a record in the Scribe Custom Actions table, and creates a required number of records in the Scribe Action Parameters table. The ResetToDefaults method passes the 'YES' (TRUE) value to the ResetToDefaults parameter to inform calling code that the current codeunit contains the custom action and that its definition has been successfully reset. The following code sample displays the ResetToDefaults method.

Note: The OnRun trigger must be designed to stop running the codeunit in case the ResetToDefaults method returns the 'YES' (TRUE), indicating that the reset to default data is successful.

ResetToDefaults(VAR Buffer : Record "Scribe Parameters Buffer") : Boolean

// check whether 'ResetToDefaults' parameter is passed

IF NOT Buffer.GET'ResetToDefaults' THEN

EXIT(FALSE); 

// delete redundant data

CustomActions.INIT;

CustomActions.SETRANGE("Codeunit No.", CODEUNIT::"Scribe Sales Quote -> Order");

IF CustomActions.FINDFIRST THEN

CustomActions.DELETE(TRUE); 

// create 'Convert Sales Quote to Order' custom action definition

CustomActions.INIT;

CustomActions.Name := 'ConvertSalesQuote';

CustomActions.Description := 'Convert Sales Quote to Order';

CustomActions."Codeunit No." := CODEUNIT::"Scribe Sales Quote -> Order";

CustomActions."Codeunit Name" := 'Scribe Sales Quote -> Order';

CustomActions.INSERT;

// create 'Convert Sales Quote to Order' custom action parameters definition

CustomActionParameters.INIT;

CustomActionParameters."Action No." := CODEUNIT::"Scribe Sales Quote -> Order";

CustomActionParameters."No." := 1;

CustomActionParameters.Name := 'QuoteNoToConvert';

CustomActionParameters.Description := 'Sales Quote number to convert';

CustomActionParameters.Type := CustomActionParameters.Type::"In";

CustomActionParameters.INSERT;

CustomActionParameters.INIT;

CustomActionParameters."Action No." := CODEUNIT::"Scribe Sales Quote -> Order";

CustomActionParameters."No." := 2;

CustomActionParameters.Name := 'ConvertedOrderNo';

CustomActionParameters.Description := 'Converted Sales Order number';

CustomActionParameters.Type := CustomActionParameters.Type::Out;

CustomActionParameters.INSERT;

// 'ResetToDefaults' parameter will be set to 'YES'

Buffer.Value := FORMAT(TRUE);

Buffer.MODIFY;

EXIT(TRUE);

The following table displays the local variables defined for this procedure.

Name DataType Subtype Length
CustomActions Record Scribe Custom Actions  
CustomActionParameters Record Scribe Action Parameters  

See also

Activating The Insight Actions