I want to create a function which returns a String. To achieve this I have followed the below steps –
1) Created a Method in BPM studio 10.3.1.0 by navigating through Catalogue component->BPM Object->Right click on the BPM object and select New Method->Give any name for method. (I gave “sample_Method“).
2) “sample_Method” method window opened in the BPM studio.
3) As my method should return a string, I placed my code in the “sample_Method” method window as below –
String strMsg = “The String to be returned”;
But after I place the above code and when compiled an error message saying “return statement can only be present in functions.” was displayed in BPM studio.
I tried many options but was unable to fix this error. After lot of struggle and research finally I was able to fix this issue.
In order to return a string from a method, we need to create a Function. To know how to create a Function from a Method, please click here.
Only Function can return something, but not a Method. So by defining the Return Type, a Method becomes a Function.