user3376708
user3376708

Reputation:

How to map a document list in WEBMethods?

I want to map an array which in WebMethods is a document list. I thought that you could just map that variable over without mapping all of the children. I have done this and nothing shows in the PassArea. (PassArea is the data array that is being sent to a mainframe program afterwards.)

     A           -->         B
       Field1                 F1
       Field2                 F2
       field3                 F3

The document is A and the input document into the Natural program is B. The --> is the link that connects them together.

I don't have an image to show, because that would reveal some company information.

Upvotes: 3

Views: 11486

Answers (2)

Ivan Herlambang
Ivan Herlambang

Reputation: 398

There's a lot ways to map between arrays of documents. But before you create one, consider these writings:

  1. Techcommunity SoftwareAG - performance impact with appendToDocumentList
  2. quest4apps.com - Reason to avoid appendToDocumentList

As hint from #2 said that there's 6 ways they ranked as follows from fastest to slowest (but I'm going to give an example in first three, because the latter three is quite obviously slow, which considered to be avoided):

1. Java Loop: looping done through a Java service.

  • The easiest way to create java service is to map the input output first. input output doc
  • Right-click and click on "Generate Code" until the dialog box appears Generate code for Implementing Service Choose the option "For implementing this service" Generated service And the service is created
  • Just re-arrange the code into this:
public static final void mappingDocuments(IData pipeline) throws ServiceException {

    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    
    // Instantiate input A
    IData[] A = IDataUtil.getIDataArray(pipelineCursor, "A");
    
    // Initiate output B
    IData[] B = new IData[A.length];
    
    if (A != null)
    {
        for (int i = 0; i < A.length; i++)
        {
            // Populate the Field in doc A
            IDataCursor ACursor = A[i].getCursor();
            String Field1 = IDataUtil.getString(ACursor, "Field1");
            String Field2 = IDataUtil.getString(ACursor, "Field2");
            String Field3 = IDataUtil.getString(ACursor, "Field3");
            ACursor.destroy();
            
            // Create IData[i] and cursors finally put all Fields into B[i] variable output
            B[i] = IDataFactory.create();
            IDataCursor BCursor = B[i].getCursor();
            IDataUtil.put(BCursor, "F1", Field1);
            IDataUtil.put(BCursor, "F2", Field2);
            IDataUtil.put(BCursor, "F3", Field3);
            BCursor.destroy();
    
            // OR JUST USE CLONE BELOW IF YOU DON'T HAVE ANY MODIFICATION INSIDE THE VARIABLE
            // B[i] = IDataUtil.clone(A[i]);
        }
    }
    pipelineCursor.destroy();
    
    // Finally to put the B Map(IData) to output.
    // Actually you can use only single pipelineCursor throughout all code but it's just for readable
    IDataUtil.put(pipelineCursor, "B", B);
    pipelineCursor.destroy();
        
}
  • Result resultJavaService

2. Implicit Loop: for simple lists of the same size, you may want to link them directly in a MAP step

  • Create flow service and input & output document
  • Create MAP step
  • Select both document in ForEach loop. ForEach

3. Explicit Loop: using a LOOP step and its Output Array.

  • Create flow service and input & output document
  • Create LOOP step
  • Change the properties of LOOP, input array=A; output array=B; and create a map under LOOP step LoopProperties
  • Map all parameters in A to B MapAtoB

Hope these helps...

Upvotes: 1

TchiYuan
TchiYuan

Reputation: 4278

If the fields of document list "A" has different names than the fields of document list "B" then no, you cannot map document list "A" to document list "B". WebMethods doesn't know which field from A corresponds to what field from "B".

You will have to do the following:

  1. LOOP over document list "A"
  2. Map each field of "A" to a generic document containing the same fields as document list "B"
  3. Append the generic document to document list "B"
  4. Drop the generic document.

Step #2 screenshot

Step #2 screenshot

Step #3 screenshot

Step #3 screenshot

Upvotes: 7

Related Questions