Creating a Document Reference in a Java service

This seems kind of basic, but it’s something I haven’t done before. In Flow I can put a new document reference in the pipeline by simply clicking the right item in a drop-down list. How do I do this in Java?

I tried something like:

IData newDoc = IDataFactory.create(“folder.folder:DocName”);

but it seems to be returning a NullPointerException. Any ideas? Thanks.

1 Like

As far as I know you’d have to manually build your IData structure in java or invoke a flow service from java that would return your reference. The best thing to do in my opinion is generate the doc reference in a flow service and pass it into java (if required). If you can use flow services to manipulate the record you’ll be much better off! But I’m sure you have a good reason for wanting to do this!

Thanks Will. I do have to manipulate the record in my Java service, but that is called from a Flow service. So I can indeed pass the (empty) record into the Java service when I invoke it, and then add to it as necessary.

I’d be kind of unhappy however, if there is in fact no way to create a new record via the Java API based on an existing document type. It truly appears as though IDataFactory.create provides for this, and I just haven’t given it what it wants. The JavaDoc says it takes the name of a class on which to base the new object. Assuming the document type was implemented as a class internally, I gave it the name of the document type. Maybe this was a poor assumption? Or maybe I didn’t reference the document type properly?

In any case, I’ll give your suggestion a try for the time being. Thanks!

You may be right. To quote the javadocs: “Returns an IData object created from a specified class. You can use this method to construct a customized IData object instead of the default IData object produced by this IDataFactory.”

I’m not sure if this reference is to the documents we create or how to get the actual class name even if this is possible.

If you think long enough you may come up with a simpler solution. I know that I have avoided using the java API to walk the document tree for over 2 years now! If you want to explain in detail what you are doing I may be able to help give you some ideas.

Well this is turning out to be much harder than it seemed, even just passing in a skeleton and manipulating it is presenting various challenges. Here’s what I’m trying to do, though.

My Java service communicates with a legacy process to send it input parameters and receive its output. I can’t do this in Flow because I have to connect to the legacy process on a socket and send it data in XDR format (essentially 4-byte packets). The output is then read off the socket and used to build a response document, which should be in the pipeline when the service completes.

Now I could:

  1. Build each node in the document manually and then insert the structure in the pipeline - I was trying to avoid this, however.
  2. Create each response node independently and return them all as separate pipeline variables. Then I could use flow to map them all into the response document.

It seems that neither of these should be necessary, since (IMO) the Java API should expose all the functionality available in the GUI in some shape or form. So I thought I should be able to create a template document based on my pre-defined document type and navigate/manipulate it as necessary. For the time being, it looks like I’m going to revert back to option 1).

Hi Michael, did you manage to find a solution for option 2 in the end ?

Hi Steven,
No, for better or worse, we got option 1 working and moved on. I would have pursued this further with support at some point ordinarily, but our project got axed just before completion. So if you still need to do something of this sort I’d suggest you get in touch with support to find out more about the IDataFactory.create method.