Skip to content

Nested Documents

inno-juanal edited this page Feb 27, 2017 · 19 revisions

webMethods supports nested documents. wmboost-data makes it easier to manipulate them compared to the alternative of using IData and other classes - using IDataCursors is particularly inconvenient.

Nested Document Example

Let's assume we want to represent a simplified invoice. The invoice is linked to a client, which is a nested document.

  • id: A654
  • date: 2017-02-12
  • totalAmount: 340.00
  • client

Populating a Nested Document

Let's populate the document in code

Document invoice = Documents.create();
invoice.entry("id").put("A654");
invoice.entry("date").put("2017-02-12");
invoice.bigDecimalEntry("totalAmount").putConverted("340.00");

Document client = invoice.docEntry("client").putNew();
client.entry("id").put("AC880");
client.entry("businessName").put("ACME");
client.entry("email").put("acme@example.org");

The most important part is the use of docEntry and putNew. This allows us to put and create a nested document in one go.

An alternative would've been to create the client first and link it to the invoice at the end:

Document client = Documents.create();
// Set client values

// Init all invoice values but client

invoice.docEntry("client").put(client);

It's possible to use entry instead of docEntry, resulting in code like invoice.entry("client").put(client). Still, the use docEntry may be preferred due to its compilation safety.

Getting a Nested Document

If we wanted to get an attribute from the nested document in another service, we could do this:

Document pipeDoc = Documents.wrap(pipeline);
Document invoiceDoc = pipelineDoc.docEntry("invoice").getNonNullVal(); 
Document clientDoc = invoiceDoc.docEntry("client").getNonNullVal();
String businessName = clientDoc.stringEntry("businessName").getVal();
// do something with the business name