Sample API Code for Journal Entry

The Journal Entry SDK is provided with the Journal Entry .car file and contains everything envisaged for those wishing to customize the Journal Entry process to meet customer requirements.

This article describes how the Journal Entry SDK can be used to update and control the state of a Journal Entry request and its instances.

The journal-entry.car file includes the SDK as part of the REDWOOD.Redwood_JournalEntry library. Specifically, the journal_entry_sdk_lib and the journal_entry_api_lib entries contain the classes for use with the SDK. To access these classes with a JobDefinition that will use them, ensure that the LibraryClosed An object used to store RedwoodScript code so that it can be easily re-used in other objects. is set to Redwood_JournalEntry.

JournalEntryService

The JournalEntryService class is the entry point for the SDK and supports two operations:

  • Reading header and line item fields;

  • Updating Journal Entry instances.

In both cases, the calls rely on having the request IDClosed The unique identifier of an item. and the instance ID for the Journal Entry instance. These are from the configured JobChain that is called by the Redwood_JournalEntry_Submit JobDefinition.

Persistence of changes made to the underlying entities via calls to the SDK are required to be handled in custom code. It is the responsibility of the custom code calling the SDK methods to persist the changes on the SchedulerSession as required.

Reading Header and Line Item Fields

Information about Journal Entry instance structure is useful when determining what data should be updated. Use the read method on the JournalEntryInstanceService while submitting a request object with the details of the relevant field information that should be obtained.

import com.redwood.scheduler.custom.app.journalentry.api.request.ReadFieldsRequest;

import com.redwood.scheduler.custom.app.journalentry.api.response.ReadFieldsResponse;

import com.redwood.scheduler.custom.app.journalentry.api.service.JournalEntryService;

...

/*

* Create the ReadFieldsRequest object and set the desired request ID and

* instance ID

*/

final ReadFieldsRequest request = new ReadFieldsRequest();

request.setRequestId(requestId);

request.setInstanceId(instanceId);

/**

* Call the static read method on the JournalEntryService class passing in the

* SchedulerSession and request and assign to a ReadFieldsResponse member

*/

final ReadFieldsResponse response = JournalEntryService.read(session, request);

/*

* Use the ReadFieldsResponse object to obtain access to the header and line

* item fields defined for the Journal Entry instance

*/

response.getHeaderFields();

response.getLineItemFields();

...

Updating Journal Entries

Updating JournalEntryService allows the management of instances in a Journal Entry request. It enables updating the following attributes of an instance:

  • Status - Indicates which stage of processing the instance is in.

  • Messages - Displays the instance, headers, line items, and data within a line item that can be set for the Journal Entry user interface.

  • Approvals - Manages approvals for a Journal Entry.

  • Line Items - Adds line items to a Journal Entry instance. For example, as part of a process where an instance requires reversals calculated after the Journal Entry is submitted.

  • Metadata - Enriches information held centrally for Journal Entry instances.

import java.util.List;

import java.util.stream.Collectors;

import com.redwood.scheduler.api.uow.SchedulerSessionUnitOfWorkManager;

import com.redwood.scheduler.api.model.enumeration.SubjectType;

import com.redwood.scheduler.custom.app.journalentry.api.enums.ApprovalStatus;

import com.redwood.scheduler.custom.app.journalentry.api.enums.FieldType;

import com.redwood.scheduler.custom.app.journalentry.api.enums.InstanceStatus;

import com.redwood.scheduler.custom.app.journalentry.api.enums.MessageType;

import com.redwood.scheduler.custom.app.journalentry.api.model.Approval;

import com.redwood.scheduler.custom.app.journalentry.api.model.Instance;

import com.redwood.scheduler.custom.app.journalentry.api.model.InstanceRow;

import com.redwood.scheduler.custom.app.journalentry.api.model.Message;

import com.redwood.scheduler.custom.app.journalentry.api.model.Metadata;

import com.redwood.scheduler.custom.app.journalentry.api.request.ReadFieldsRequest;

import com.redwood.scheduler.custom.app.journalentry.api.request.UpdateRequest;

import com.redwood.scheduler.custom.app.journalentry.api.response.ReadFieldsResponse;

import com.redwood.scheduler.custom.app.journalentry.api.response.UpdateResponse;

import com.redwood.scheduler.custom.app.journalentry.api.service.JournalEntryService;

{

final SchedulerSessionUnitOfWorkManager uowManager = new SchedulerSessionUnitOfWorkManager(() -> jcsSession);

 

final UpdateRequest request = new UpdateRequest();

request.setRequestId(requestId);

final Instance instance = new Instance();

instance.setRequestId(requestId);

instance.setId(Long.valueOf(instanceId.longValue()));

 

instance.setStatus(InstanceStatus.PREPARING);

 

request.setInstances(List.of(instance));

 

uowManager.perform(session -> {

JournalEntryService.update(session, request);

});

/*

* Messages are available in different types and can be associated with:

* -> The instance, by setting only the instance ID

* -> A specific row (header or line item) setting the RowId from the RTX of the instance

* -> A specific field (header or line item) setting the FieldId from the instance

*

* Information about fields can be obtained via a call to the JournalEntryService.read method

*/

final Message infoMessage = new Message();

infoMessage.setInstanceId(Long.valueOf(instanceId.longValue()));

infoMessage.setMessageType(MessageType.INFO);

infoMessage.setMessage("This is an informational message");

infoMessage.setCustomReference("Some custom value");

instance.setMessages(List.of(infoMessage));

 

uowManager.perform(session -> {

JournalEntryService.update(session, request);

});

 

/*

* Approvals can be updated using the SDK if required.

* note: this will create the approval if it doesn't already exist

*/

final Approval approval = new Approval();

approval.setInstanceId(Long.valueOf(instanceId.longValue()));

approval.setStage(Long.valueOf(1));

approval.setStatus(ApprovalStatus.REJECTED);

approval.setSubjectId(jcsSession.getSubjectByTypeName(SubjectType.User, "admin").getUniqueId());

approval.setTimestamp(Long.valueOf(System.currentTimeMillis()));

instance.setApprovals(List.of(approval));

 

uowManager.perform(session -> {

JournalEntryService.update(session, request);

});

 

/*

* Metadata can be associated with the instance or with individual rows (header and line items)

*/

Metadata metadata = new Metadata();

metadata.setId(Long.valueOf(1));

metadata.setTechnicalName("ERPClosed Enterprise resource planning (ERP) refers to a type of software that organizations use to manage day-to-day business activities such as accounting, procurement, project management, risk management and compliance, and supply chain operations. A complete ERP suite also includes enterprise performance management, software that helps plan, budget, predict, and report on an organization’s financial results._Posting_No"); // note: there will be some well defined metadata technical fields that will have a direct impact on the data displayed in the Journal Entry user interface

metadata.setDisplayName("The ERP Posing Number");

metadata.setValue("abc123");

instance.setMetadata(List.of(metadata));

 

uowManager.perform(session -> {

JournalEntryService.update(session, request);

});

 

/*

* To add header and line items to the instance we need to first obtain information about the fields

* available on the instance itself.

*/

final ReadFieldsResponse[] readFieldsResponse = new ReadFieldsResponse[1];

final ReadFieldsRequest readFieldsRequest = new ReadFieldsRequest();

readFieldsRequest.setRequestId(requestId);

readFieldsRequest.setInstanceId(Long.valueOf(instanceId.longValue()));

 

uowManager.perform(session -> {

readFieldsResponse[0] = JournalEntryService.read(session, readFieldsRequest);

});

 

/*

* InstanceRow is a generic class that can be used to hold information about header and line items

* Adding and Updating the header row is not supported

*/

final InstanceRow lineItem = new InstanceRow();

lineItem.setFieldType(FieldType.TECHNICAL_ROW); // we can add technical rows that are not considered part of the original instance data submitted to the ERP system

lineItem.setFields(readFieldsResponse[0].getLineItemFields().get().stream().collect(Collectors.toMap(entry -> entry.getFieldId(), entry -> "My Field Value")));

metadata = new Metadata();

metadata.setId(Long.valueOf(1));

metadata.setTechnicalName("Line Item Metadata"); // note: there will be some well defined metadata technical fields that will have a direct impact on the data displayed in the Journal Entry user interface

metadata.setDisplayName("Line Item Metadata");

metadata.setValue("abc123");

lineItem.setMetadata(List.of(metadata));

instance.setLineItems(List.of(lineItem));

 

uowManager.perform(session -> {

JournalEntryService.update(session, request);

});

}