Object Status Update via Custom Trigger - How To?

Posted by cohezive on 05-Apr-2015 09:58

There is a DataObject method called setStatus that requires a Status object (an enum?) as a parameter.  Unfortunately, there is also no documentation about the Status class and how to identify the value to be passed in the parameter.

Since the status field is an id to a Workflow Status object, how do you acquire the valid values setting (new) or updating (change) the status on a DataObject?

Posted by cohezive on 11-May-2015 14:38

So, tor now (because getByName() is not available), what I have had to do is:

1)  Make certain that all the Workflow Statuses are in the same Workflow Process

     Note:  This requires Triggers or Workflow Actions to be built to assign an action even it will never be used.

2)  Iterate through the results of DataObject.getProcess().getAllStatuses() for the object for the Workflow Process associated with the current status (normally default) and perform a code compare (status.getCode()).  When the correct status is found, save it.

3)  Call DataObjectHandler.setStatus(runner.getTransaction(), data, newStatus, runner.getUser(), runner) to save the status.

This appears to be working without any issues.

All Replies

Posted by Santosh Patel on 25-Apr-2015 22:55

You can use StatusHandler.getByName(DataObjectDef objDef,  String systemCode)

objDef - the object definition that you are dealing with myDataObj.getObjectDef()

systemCode - integration name for the workflow status field in your object

Posted by cohezive on 27-Apr-2015 23:22

Care to identify which library this is in?  It does not appear in any of the normal jar files.

Posted by Santosh Patel on 28-Apr-2015 01:06

Apologies. The class is apparently obfuscated and not  exposed as a public interface.

Could you try using DataObject.getProcess().getAllStatuses() ? All classes are from rb_core.jar.

Posted by pvorobie on 28-Apr-2015 09:14

That will return List<Status> assigned to workflow process. But please check first whether Process is null or not :)

Posted by pvorobie on 30-Apr-2015 13:06

I do not recommend using DataObject.setStatus() API since it will not make changes persistent. Use DataObjectHandler.setStatus() instead. Pass ID of status you wish to set. Example:

DataObjectDef objDef = DataObjectDefHandler.getByName(runner.getCustomer(), "invoice");

DataObject data = DataObjectHandler.getDataObject(runner.getCustomer(), objDef, id);

Status newStatus = StatusHandler.getByName(objDef, "posted");

DataObjectHandler.setStatus(runner.getTransaction(), data, newStatus, runner.getUser(), runner);

Posted by cohezive on 30-Apr-2015 14:24

Thanks - I caught that - and was forced into doing a supplemental update to persist the change.  Much better to use the single step.

Posted by pvorobie on 30-Apr-2015 14:37

Are you using any other Rollbase Java APIs or planning to use? I'm working on providing code samples and guidelines in JavaDoc.

Posted by cohezive on 10-May-2015 20:00

StatusHandler is not available in the APIs.   As Santosh posted above: the class is apparently obfuscated and not  exposed as a public interface.

Posted by pvorobie on 11-May-2015 11:28

I confirm that StatusManager class and other classes from Workflow package are obfuscated. I'll check with management whether we want to open these classes for 3rd-party developers.

Posted by cohezive on 11-May-2015 14:38

So, tor now (because getByName() is not available), what I have had to do is:

1)  Make certain that all the Workflow Statuses are in the same Workflow Process

     Note:  This requires Triggers or Workflow Actions to be built to assign an action even it will never be used.

2)  Iterate through the results of DataObject.getProcess().getAllStatuses() for the object for the Workflow Process associated with the current status (normally default) and perform a code compare (status.getCode()).  When the correct status is found, save it.

3)  Call DataObjectHandler.setStatus(runner.getTransaction(), data, newStatus, runner.getUser(), runner) to save the status.

This appears to be working without any issues.

Posted by pvorobie on 11-May-2015 15:33

Yes, that should work.

Posted by Santosh Patel on 12-May-2015 00:11

Sorry for the trouble. Like Pavel said, we will check and see if there is a possibility to make this easier. Thanks for your patience. :)

This thread is closed