Skip to main content

Hello,

How to set up auto-incrementation for a field in a custom entity?

 

I didn’t see any option available in the interface.

I saw that it’s possible to use a number counter, but I’m not sure how to link it to a field of my entity through the interface.

 

 

Thank you in advance for your help.

Hi ​@NINO,

You need to create a Persistent type field where data type should be String.

Select PLSQL option for default value and enter below method.

DOC_NUMBER_COUNTER_API.FETCH_NEXT_NUMBER('EVENTBUS','-')

Hope this helps.

 

Regards

Abdul Rehman 


Hi ​@Abdul 

1) I tried DOC_NUMBER_COUNTER_API.FETCH_NEXT_NUMBER('EVENTBUS', '-') but it didn’t work, and even when I set a hardcoded value, it doesn’t appear in my table.

 

 

For my tests, I’m using an OData call on my custom projection CustomProjectionTESTNINOTAB.

But the ID column is still null.

 

  1. However, this call works fine.

SELECT IFSAPP.DOC_NUMBER_COUNTER_API.FETCH_NEXT_NUMBER('EVENTBUS','-') FROM DUAL

 

 

 


Hi ​@NINO,

First, counter value would be null for existing records, so better check by creating by some new records.

Second, use PL/SQL Expression option to get default value.

Please check above suggestions and let me know if you need further assistance.

 

Regards 

Abdul Rehman 


Hi ​@Abdul 

Thanks for your feedback.

As I mentioned earlier, I already tried using:

 

DOC_NUMBER_COUNTER_API.FETCH_NEXT_NUMBER('EVENTBUS', '-')

For testing, I’m using an OData call on my custom projection CustomProjectionTESTNINOTAB,
but the ID column still remains null.

 

However, when I run this directly in SQL:

SELECT IFSAPP.DOC_NUMBER_COUNTER_API.FETCH_NEXT_NUMBER('EVENTBUS', '-') FROM DUAL

 

it works perfectly.

Do you have any idea why the default value or PL/SQL expression isn’t being applied when inserting through OData?

 

Thanks again for your help.


@NINO you can’t call the procedure directly in SQL Developper, you need to call it threw dual for exemple or using a variable to store the return result

.

BUT

when adding a custom field the call could be added directly : 

 

 

 

I have created a custom entity and page 

 

 

Works well from my end


Hi everyone,

Thanks for your help and suggestions.

I finally found why the PL/SQL default value wasn’t applied when inserting data through OData.

In fact, when using a custom entity and projection, the default value isn’t triggered by a simple POST on the Projection Set.
You must call the Default action of the projection, which initializes the record and executes the PL/SQL default expression.

 

This endpoint works:

…/main/ifsapplications/projection/v1/CustomProjectionAqEventBusTabNINO2.svc/AqEventBusTabNINO2Set/IfsApp.CustomProjectionAqEventBusTabNINO2.AqEventBusTabNINO2_Default()

 

This automatically triggers my PL/SQL expression:

DOC_NUMBER_COUNTER_API.FETCH_NEXT_NUMBER('EVENTBUS','-')

 

After that, the field is correctly populated and no longer remains NULL.

Posting this in case it helps someone else running into the same issue!

Regards,
NINO