Flow generation programmatically

Hi Folks,

I would like to know how to generate a flow service with steps by using custom java service or any root service? Is there any hidden methods exist? Thanks in advance


Hi Mohan,

This possiable in webMethods, I have see those services & used them.

i haven’t developed them, but cule is “you need make use webMethods API and write java services to acheive this”

i am also very interested to find out this

Thanks Sai, By any chance do u remember those webMethods APIs or could you add some more light on this?

What webMethods API’s are you talking here you mean Java API here?

Yes webMethods Java API only.It was just a though of my self, that it can be done in java

Even services that i have seen are of java services and i didn’t get a chance to look into code.

Do you have any idea we can acheive this, i want to make try on this

Yes rmg, we are talking about java API, I see there is a public API “registerFlowService” but not sure this can be used and how to use this. Could you share your idea?

I have not used this function before and probably API documentation can give some idea.

Will have any clue surely update forum back:


AFAIK, there are no pubilcly available Java API’s from SAG to create Flow services on the fly. Having said that, you can look at the flow.xml file when an empty service is created and then use that to create a flow service with all the required tags from a Java program.

Unless you have a template on what settings\steps(try\catch sequence,logging etc) need to be created for this automation, it will be on no use in real world.

Yes that’s the better option to start with…but it sounds like there is no direct solution from API:)

So u are saying that write a flow.xml file with required nodes into IS.Is it like we are creating a manual file into the IS,right?will it make a sense?

I know this topic been awhile but does anyone successfully programmatic generate a Flow service? If yes, could you please share the information? Thanks!

Hi Jenny,

Yes. I have written such code which can generate flow on the fly or programmatically. Below is a sample which can generate either an empty flow or a flow defaulted with try catch using trident sequence.

import com.wm.app.b2b.server.ns.Namespace;
import com.wm.lang.flow.FlowRoot;
import com.wm.lang.flow.FlowService;
import com.wm.lang.ns.NSName;
import com.wm.lang.ns.NSPackage;
import com.wm.lang.ns.NSService;
import com.wm.lang.ns.NSServiceType;

public void createEmptyFlow(NSName nsName, boolean createWithTryCatch) throws Exception {
		Namespace ns = Namespace.current();		
		NSService service = createFlow(pkg, nsName, ns);
		if (createWithTryCatch){
			FlowRoot flowRoot = generateTryCatchCode();
			if ((flowRoot != null) && (service != null)) {
private NSService createFlow(String pkg, NSName nsName, Namespace ns) throws Exception {		
		NSServiceType stype = NSServiceType.create("flow", "default");
		NSPackage nsPkg = ns.getPackage(pkg);
		NSService service = ns.createService(nsPkg, nsName, stype);
		return service;
private FlowRoot generateTryCatchCode(){	  	  
		// Try-Catch Sequence
		Object[][] sqSuccess = {
				{ "type", "SEQUENCE" }, 
				{ "comment", "--- main ---" }, 
				{ "exit-on", "SUCCESS" } };
		Object[][] sqFailure = {
				{ "type", "SEQUENCE" }, 
				{ "comment", "--- try ---" }, 
				{ "exit-on", "FAILURE" } };
		Object[][] sqDone = {
				{ "type", "SEQUENCE" }, 
				{ "comment", "-- catch --" }, 
				{ "exit-on", "DONE" } };
		IData sqSuccessData = IDataFactory.create(sqSuccess);
		IData sqFailureData = IDataFactory.create(sqFailure);
		IData sqDoneData = IDataFactory.create(sqDone);
		FlowSequence fss = new FlowSequence(Values.use(sqSuccessData));
		FlowSequence ffs = new FlowSequence(Values.use(sqFailureData));
		FlowSequence fds = new FlowSequence(Values.use(sqDoneData));
		// Get Last Error Invoke
		Object[][] getLastError = {
				{ "type", "INVOKE" }, 
				{ "comment", "" }, 
				{ "service", 
				"pub.flow:getLastError" } };
		IData getLastErrorData = IDataFactory.create(getLastError);
		FlowInvoke getLastErrorInvoke = new FlowInvoke(Values.use(getLastErrorData));

		// Root composition
		Object[][] rootValues = { { "type", "ROOT" } };
		IData flowRootData = IDataFactory.create(rootValues);
		FlowRoot flowRoot = new FlowRoot(Values.use(flowRootData));
		return flowRoot;
1 Like


Sounds interesting, but I am not sure if there is a real business case to do such things.

If you known one, please share it.


Even, I am also interested to know the business use-case on this.


One of the typical use cases could be creating wrapper/template services in the key framework components where framework controls the creation of services that invokes target based on user defined rules. This mostly helps development teams to avoid writing repetitive code and control the environment the framework wants. I was writing code for some of the key customers who invested in development of such frameworks for healthy and controlled development of the projects.

Thank you Prasad for the example.

For my case, we got a lot of mapping already done in the excel spreadsheet. Therefore, I’m wondering if it possible to load those spreadsheet and create a Flow Service out from it. I’m trying to see if I can reverse engineer the flow.xml.

If it involves lot of mappings or iterative or nested document structures then the more complex it becomes to create the flow. You may have to invest lot of time to achieve the same if it is really worth

If you have most of the mapping rules in excel, it’d suggest to generate xslt map instead. It’s much transparent than generating flow service.
you can also create/run xslt services in WM IS easily.

Thank you Prasad for the example.

I work with the version 9.12 of webMethods. Wheni create a java service with your code, i have a problem with a conversion :

com.wm.lang.ns.NSService not cast to com.wm.lang.flow.FlowService;

The problem is in this line : ((FlowService)service).setFlowRoot(flowRoot);

I try to play with the different API but i’m lost.

Do you have a idea ?

Thank you.