rbv_api.getRelatedIds() causes Java exception when used with create in Java extension - Forum - Rollbase - Progress Community

rbv_api.getRelatedIds() causes Java exception when used with create in Java extension


rbv_api.getRelatedIds() causes Java exception when used with create in Java extension

  • 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. 

  • 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.

  • 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.

  • No IDs related to which record?

  • 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?
  • 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.

  • 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.

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

  • 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.
  • I'm not talking about related records. ID passed to rbv_api.getRelatedIds() points to core record. And that record must exist.

  • 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.

  • 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.

  • 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.

  • 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?

  • 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.