Accounting API Developer's Reference
|
c2g.IOnlineInquiryActionglobal interface IOnlineInquiryAction You can use the c2g.IOnlineInquiryAction global interface to invoke custom actions from Action Views.
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
invokeActionOnlineInquiriesService.ActionResult invokeAction(c2g.DataViewService.DataView dataview, c2g.SelectionService.Result selectedData, String actionParameter, Map<String, String> promptValues) Invokes the action. Input Parameters
Return ValueThis method returns a c2g.OnlineInquiriesService.ActionResult object. getParameterMetadataListList< DataViewService.ParameterMetadataType> getParameterMetadataList() Dictate any parameters to be supplied by the user at runtime. Return ValueThis method returns a list of type c2g.DataViewService.ParameterMetadataType. isSingleSelectBoolean isSingleSelect() Indicates if the action applies to single or multiple rows. Return ValueThis method returns a Boolean: true when the action applies to single rows, false when the action applies to multiple rows. getRequiredFieldsSet<Id> getRequiredFields(c2g.DataViewService.DataView dataview) Tells FinancialForce which fields it needs from the dataview. Input Parameters
Return ValueThis method returns a Set<Id>: This is a set of dataview field ids to be included in any data selection. |