Facing Run-time issue in common groovy script while using Engine API.

Hi All,
We are facing the run-time issue while using The Engine API in common groovy script (Development–>Manage Groovy script–>(Create new groovy Script))

Run-time Issue:
groovy.lang.MissingPropertyException: No such property: apiAccessor for class: CommonScriptTest

Common Groovy Script Code:

import groovy.json.*;
import org.bonitasoft.engine.api.ProcessAPI;
import org.bonitasoft.engine.api.ProcessRuntimeAPI;
import org.bonitasoft.engine.api.APIAccessor;
import java.util.logging.Logger;
import java.util.logging.Level;

def setValueToProcessVariable(def connResult,long processInstanceId) {
Logger log = Logger.getLogger(getClass().getName());
log.setLevel(Level.findLevel(“INFO”));
def slurper = new JsonSlurper();
def parseResult = slurper.parseText(connResult);
log.info(“setValueToProcessVariable -------------> start ::” +processInstanceId);
Map<Object,Object> map=new HashMap<Object,Object>();
if(parseResult!=null){
String cusID=parseResult.customerID;
log.info("customer ID : "+cusID);
custID = Integer.parseInt(cusID);
custName = parseResult.c_name;
log.info("custName : "+custName);
custAddress = parseResult.c_address;
log.info("custAddress : "+custAddress);
custZip =parseResult.zipCode;
log.info("custZip : "+custZip);
map.put(“cus_ID” , custID);
map.put(“cus_Name”, custName);
map.put(“cus_Address”, custAddress);
map.put(“cus_Zip”, custZip);
apiAccessor.getProcessAPI().updateProcessDataInstances(processInstanceId, map);
log.info(“setValueToProcessVariable -------------> end”);
} }

Log Files:
groovy.lang.MissingPropertyException: No such property: apiAccessor for class: CommonScriptTest
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at CommonScriptTest.setValueToProcessVariable(CommonScriptTest.groovy:37)
at CommonScriptTest$setValueToProcessVariable.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at BScript2.run(BScript2.groovy:31)

Kindly help me to provide a way to achieve. Deeply looking for your valuable response.

Thanks,
Rajiv M

1 Like

Hi,

This is a scope issue.

The Groovy function created through the Manage Groovy script menu are available anywhere in your process. All the functions created in one file will be part of the same Class.

So either you define you function static to call them without instantiating a new object or you instantiate a new object and use its methods.

In any case, you need to pass the context of execution. In your case, if you need to use apiAccessor, you either need to pass it to the function that use it or to pass it at the object instantiation.

Cheers

hi,
Same error.
someone to help us with this error.

A Tip on displaying CODE/LOGS correctly in Posts:

Do not use the Supplied Buttons above, for some reason they refuse to work correctly, and despite bringing it to Bonitasofts attention, it’s low priority.

To Show Code/Logs correctly use

< code >
your code/log
< /code >

removing the spaces to allow the showing of code/logs correctly as here:

your code/log

You should still be able to edit your post to ensure the correct formatting of the code to help us understand it easier.

Thanks and regards
Seán

Hi Sean Mcp,
Thank you so much for your response.
As you requested, I have edited the post. Kindly help me to resolve the issue.

Thanks in Advance

Regards,
Rajiv M

Hi Lionel Palacin,

Thanks man :slight_smile: thank you so much :slight_smile:
it’s worked as you suggested:):), I have passed apiAccessor to the function and handled over there :slight_smile:

Cheers :slight_smile:

Regards,
Rajiv M