Accounting API Developer's Reference

c2g.IOnlineInquiryAction

global interface IOnlineInquiryAction

You can use the c2g.IOnlineInquiryAction global interface to invoke custom actions from Action Views.
To use this interface you must:

  1. Write a custom Apex class for the action. The Apex class name must start with 'OLIAction'. The Apex class name (including <prefix>.) must not be more than 60 characters.
  2. Implement the c2g.IOnlineInquiryAction interface.
  3. Provide four methods for the class. These methods are detailed below.
Further Notes:
  • The Apex class must include error handling.
  • The Apex class must return a status message to the user interface (for example, Success or Failed).
  • The Apex class must inform the user interface if a refresh is required (so that the latest status information can be displayed).
  • It is essential that you test custom actions in your sandbox before putting them into production.

Packaged Action
FinancialForce Accounting provides a sample Apex class for updating sales invoice due dates. For details of how to configure this class and perform the action, see the FinancialForce Accounting Help topic "Using the Sample Action to Update Sales Invoice Due Dates".

Sample Code

//Note: This sample code is for demonstration purposes only, it is not intended for
//use in a production environment, is not guaranteed against defects or errors and
//is in no way optimized or streamlined.

//The following is a generic example. Note that it has not been fully tested and is a representation only.
public class OLIActionExample implements c2g.IOnlineInquiryAction
{
    private static final String INVOICE_ID = 'InvoiceId';
    private static final String MY_DATE = 'MY_DATE';

    public OLIActionExample()
    {
    }

    // Is the action only allowed on single select?
    public Boolean isSingleSelect()
    {
        // Ours is a multi-select action
        return false;
    }

    public Set<Id> getRequiredFields(c2g.DataviewService.Dataview dataview)
    {
        return new Set<Id>{getFieldByName(dataview, INVOICE_ID)};
    }

    // Called to find out what information is to be provided by the user
    public List<c2g.DataViewService.ParameterMetadataType> getParameterMetadataList()
    {
        // We will request a Date named MY_DATE
        List<c2g.DataViewService.ParameterMetadataType> parameterMetadataList = 
                new List<c2g.DataViewService.ParameterMetadataType>();

        parameterMetadataList.add(
          createParameterMetadataType(MY_DATE, Label.ActionExampleDateLabel, 'DATE'));

        return parameterMetadataList;
    }

    // Called to perform our action
    public c2g.OnlineInquiriesService.ActionResult invokeAction(
        c2g.DataViewService.Dataview dataview,
        c2g.SelectionService.Result selectedData,
        String actionParameter,
        Map<String, String> promptValues)
    {
        // Validate our inputs - e.g.
        if(selectedData.Header == null)
        {
            return createActionResult(
                c2g.OnlineInquiriesService.MessageLevel.ERROR,
                Label.ActionExampleNoSelectedDataError, false);
        }
        // Find the Ids of any fields we want
        Id invoiceField = getFieldByName(dataview, INVOICE_ID);
        // Find the indexes of our fields in the resultset
        Integer invoiceIdIndex = getResultIndex(selectedData, invoiceField);
        // Complain if our data is missing
        if(invoiceIdIndex == null)
        {
            return createActionResult(
                c2g.OnlineInquiriesService.MessageLevel.ERROR,
                Label.ActionExampleInvoiceIdNotSelectedError, false);
        }
        // Read the values of our fields from the resultset
        Set<Id> invoiceIds  = new Set<Id>();
        for(c2g.SelectionService.Row row : selectedData.Rows)
        {
            Id invoiceId = (Id) row.Values.get(invoiceIdIndex);
            if(String.isBlank(invoiceId))
            {
                // Looks like this could be something other than an 
                // invoice as it has no value for invoiceId
                return createActionResult(
                    c2g.OnlineInquiriesService.MessageLevel.ERROR,
                    Label.ActionExampleInvoiceIdMissingError, false);
            }
            invoiceIds.add(invoiceId);
        }
        if(invoiceIds.size() < 1)
        {
            return createActionResult(
                c2g.OnlineInquiriesService.MessageLevel.ERROR,
Label.ActionExampleNoSelectedDataErrorNoDataRowsError, false);
        }

        // Read the ISO formatted date string from the promptValues map container.
        String promptedMyDate = promptValues.get(MY_DATE);

        // If no myDate could be extracted - report an error
        if(promptedMyDate == null)
        {
            return createActionResult(
                c2g.OnlineInquiriesService.MessageLevel.ERROR,
Label.ActionExampleMissingMyDateValueError, false);
        }
        // Convert the ISO formatted date string into a Salesforce Date object.
        Date myDate = Date.valueOf(promptedMyDate);

        // Perform our action...

        // Report successful completion of the action
        return createActionResult(
c2g.OnlineInquiriesService.MessageLevel.SUCCESS,
Label.ActionExampleCompletedTaskMessage, true);
    }

    // Example field Id detection
    private Id getFieldByName(c2g.DataviewService.Dataview dataview, String name)
    {
        for(DataviewService.Field field : dataview.Fields)
        {
            if(field.Name == name)
            {
                return field.Id;
            }
        }
        return null;
    }

    private Integer getResultIndex(c2g.SelectionService.Result selectedData, Id field)
    {
        for(Integer index = 0; index < selectedData.Header.Fields.size(); index++)
        {
            Id fieldId = selectedData.Header.Fields[index];
            if(field == fieldId)
            {
                return index;
            }
        }

        return null;
    }

    private c2g.OnlineInquiriesService.ActionResult createActionResult(
        c2g.OnlineInquiriesService.MessageLevel statusCategory,
        String statusMessage,
        Boolean requiresRefresh)
    {
        c2g.OnlineInquiriesService.ActionResult actionResult = 
new c2g.OnlineInquiriesService.ActionResult();

        actionResult.StatusCategory = statusCategory;
        actionResult.StatusMessage = statusMessage;
        actionResult.RequiresRefresh = requiresRefresh;

        return actionResult;
    }

    private c2g.DataViewService.ParameterMetadataType 
createParameterMetadataType(String key, String label, String type)
    {
        c2g.DataViewService.ParameterMetadataType metaData = 
new c2g.DataViewService.ParameterMetadataType();

        metaData.Key = key;
        metaData.Label = label;
        metaData.Type = type;

        return metaData;
    }
}

Methods

invokeAction

OnlineInquiriesService.ActionResult invokeAction(c2g.DataViewService.DataView dataview, c2g.SelectionService.Result selectedData, String actionParameter, Map<String, String> promptValues)

Invokes the action.

Input Parameters

Name Type Description
dataview c2g.DataViewService.DataView The dataview being used.
selectedData c2g.SelectionService.Result The rows on which the action is being performed.
actionParameter String Any parameter defined for the action on the dataview.
promptValues Map<String, String> A list of label-value pairs containing parameters supplied by the user at runtime (as requested by getParameterMetadataList()).

Return Value

This method returns a c2g.OnlineInquiriesService.ActionResult object.

getParameterMetadataList

List< DataViewService.ParameterMetadataType> getParameterMetadataList()

Dictate any parameters to be supplied by the user at runtime.

Return Value

This method returns a list of type c2g.DataViewService.ParameterMetadataType.

isSingleSelect

Boolean isSingleSelect()

Indicates if the action applies to single or multiple rows.

Return Value

This method returns a Boolean: true when the action applies to single rows, false when the action applies to multiple rows.

getRequiredFields

Set<Id> getRequiredFields(c2g.DataViewService.DataView dataview)

Tells FinancialForce which fields it needs from the dataview.

Input Parameters

Name Type Description
dataview c2g.DataViewService.DataView The dataview where the action is configured.

Return Value

This method returns a Set<Id>: This is a set of dataview field ids to be included in any data selection.