rbv_api.getRelatedIds() causes Java exception when used with

Posted by cohezive on 28-Apr-2015 07:35

I am using getRelatedIds() in an expression (see code from User Guide below) for an object.  When I create a new object in a Java extension, this code is throwing an exception trying to find an object that does not exist.  (Caused by: com.rb.core.services.api.ApiException: Data object with id 142815308 not found).

var arr = rbv_api.getRelatedIds("R1321", {!id});
for (var k=0; k<arr.length; k++) {
var id = arr[k];

After  some effort, the only way I found to continue to use this in an expression was to check for a Relationship field value {!R1321} for -1 (meaning it is empty).  

if ({!R1321} == -1) return;

However, clearly having getRelatedIds() return an invalid ID is not supposed to occur. 

All Replies

Posted by pvorobie on 28-Apr-2015 08:36

The error indicates that data record with id 142815308  does not exist at the time of API calling. That's all I can say based on information you provide.

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

There are no related ids at all.  The api call should return an empty array.  It is not.  The ID does not exist before or after create.  I have no clue where that ID is coming from and it's always the same ID.

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

No IDs related to which record?

Posted by Godfrey Sorita on 28-Apr-2015 11:50
I was able to reproduce the same error by using an ID which does not exist in the system. Have you tried to debug this trigger on an object record? Are you also using the {!id} token in your code?
Posted by pvorobie on 28-Apr-2015 11:58

Well, if ID does not exist in the system, you'll get an error, that seems to be right.

Please make sure that "id" parameter passed to API (which is set to {!id} template token in your script) points to an existing record.

Posted by cohezive on 28-Apr-2015 14:10

I'm issuing a create record for the main object - not the related object.  There are no related objects - and, therefore, no id's to pass.  The expression is being evaluated during the create process.

So this line:

                       var arr = rbv_api.getRelatedIds("R1321", {!id});

should return ZERO ids.  This is confirmed by the fact that the value of the Relationship field is -1.

Instead, the above API call is returning a non-existing object id.  The object doesn't exist, never existed, and is not a value I have any control over.   The work-around is testing for a -1 in the relationship field value in the main object.  The reason that works is it simply avoids making the API call that is returning an invalid value.

Posted by cohezive on 28-Apr-2015 14:12

Note this ONLY happens within the JAVA extension.  This has not occurred during rbv_api creates via triggers.

Posted by Godfrey Sorita on 28-Apr-2015 14:55

142815308 is actually the value of the second parameter in getRelatedIds() API. In your example it's the parsed value of  {!id} token. 

To verify this, please add the following script on top of your code:

rbv_api.log("debug", "{!id}");

This should display the value of the {!id} token during a transaction. You can check the logs entries by following the steps below:

  1. Go to an object definition.
  2. Edit any trigger. 
  3. Click the Log button just under the formula body.
Posted by pvorobie on 28-Apr-2015 15:06

I'm not talking about related records. ID passed to rbv_api.getRelatedIds() points to core record. And that record must exist.

Posted by cohezive on 28-Apr-2015 15:13

The expression is correct and has worked in all prior cases - except when executed by a non-ui trigger (remember that?)

I can only assume that during a Transaction-based java create call, it does not.  Yet, rollbase is executing the expression during the transaction while the object has not actually been instantiated in a way that the expression can use it.

Posted by pvorobie on 28-Apr-2015 15:29

Please share code of your Custom Rollbase trigger. If code is complex, no need to share entire code, just part which create record(s). I also wonder if you commit Transaction in your custom trigger.

Posted by cohezive on 28-Apr-2015 17:30

prodlist = DataObjectHandler.create(runner.getTransaction(), prodlistdef, pfieldmap, runner.getUser(), runner);

This is followed by a Status Update

prodlist.setStatus(status, runner.getUser().getId(), new Date());

DataObjectHandler.update(runner.getTransaction(), prodlist, pfieldmap, runner.getUser(), runner);

And setting a (different) relationship

Boolean res = RelationshipHandler.createRelationship(runner.getTransaction(), rel.getId(), data.getObjectDefId(),data.getId(), prodlist.getObjectDefId(), pid);

No, I am not committing the transaction.  The documentation indicates not to and, as shown above, there are other interactions required in the same transaction.

All of the above code is working as expected.

Posted by pvorobie on 29-Apr-2015 11:31

You should not use RelationshipHandler.createRelationship This is internal API which does not provide result you would expect.

Please use DataObjectHandler.update() instead and set long[] as value for Lookup field.

Also, to be sure, are you dealing with native Rollbase objects or with OpenEdge Objects?

Posted by cohezive on 29-Apr-2015 21:44

Thanks for the tip on the Relationship - but then why is it  in the Javadoc and part of the com.rb.core.data.definition package?   How would anyone even know what is "internal" or not when the only documentation Progress provides is the Javadoc?

Also, if this is a "many" relationship, how does that impact the fieldmap?  Isn't the relationship field an array in this case?   When assigning data.shortFieldMap to the internal variable, won't I need to manage that entire array?

Back to the point of this thread, and for the record, the relationship call was added only after I added the work-around to resolve the expression exception error on the java create call.

These are native rollbase objects.

Posted by pvorobie on 30-Apr-2015 11:29

You're right - our JavaDoc does not provide adequate guidelines for Custom triggers developers. We should fix that. Tracking issue as PSC00332094

In the mean time please ask questions if your custom Java code does not work as expected.

Posted by pvorobie on 30-Apr-2015 12:03

Are there any particular Rollbase Java APIs you're using or consider using in your code (other than mentioned already) ?

Posted by Godfrey Sorita on 30-Apr-2015 15:15


It seems that getRelatedIds will always throw this error when used on Expression Fields regardless of where they were created. Below are the replication steps:

1. Create a valid getRelatedIds call on an expression field (without the handling provided by [mention:640058581a304d6dbd13f8493c2c447b:e9ed411860ed4f2ba0265705b8793d05]).

2. Create a record from UI / JAVA custom trigger.


Posted by pvorobie on 01-May-2015 12:34

I do not confirm this issue. I created Expression field of type String with the following formula:

var x = rbv_api.getRelatedIds("R873944", {!id});

var buff = '';

if (x != null && x.length > 0) {

 for (var k=0; k<x.length; k++)

   buff += x[k]+', ';


return buff;

It works exactly as expected.

As for custom Java trigger, I repeat my question:

Are there any particular Rollbase Java APIs you're using or consider using in your code (other than mentioned already) ?

This thread is closed