Setting Is Autonumber to 'Yes, if value not set' for local Id column

Setting Is Autonumber to 'Yes, if value not set' for local Id column

  

I have a local entity with an Id attribute that references an Id of a database table (see screenshot). When I try to create a new record in this entity, I am getting an error stating that the Not Null constraint is violated.

To remedy this, I want to set the 'Is AutoNumber' propery of the local attribute to 'Yes, if value is not set'. However, the value of this property is automatically set to 'No' and I don't seem to be able to change it.

I am wondering how the value of this propery is determined, and whether I can change it after it is initially set.

Hello Rob,

You can't change this, because for this Local Entity, the Primary Key is also a Foreign Key (for a LOCAL entity).
Notice the arrow in the primary key. 

In mobile, when a primary key is also a reference attribute (FK) for another LOCAL entity, you MUST provide a valid ID for it when creating a record.

Cheers.

EDIT
P.S. While you CAN change this in Service Studio and publish, don't know if this will not cause a problem in updating the application in the device, that will make the user have to uninstall the application and install again.

In this case (if this happen, you can test it), the better would be to create a new entity and remove the old one, probably, or you can try to delete the ID and create a new one (this does not work in server entities, don't know if it will work here).

Hi Eduardo,

thanks for your reply. The thing that still puzzles me is why the value is set to 'No' instead of 'Yes, if value is not set'. In the example below, the primary key is also a foreign key but the value is set differently.

What is the logic behind the setting of this value?

Thanks,

Rob


Hi,

The logic is that in the first case, you are pointing to a LOCAL entity, and in the second, to a SERVER entity... :)

So, Expense is a LOCAL entity, and Invoice is SERVER entity.

Hi Eduardo,

I'm afraid that both Invoice and Expense are Server entities.

So I've got LocalExpense (local entity) with an Id that references Expense.Id (server entity), and LocalInvoice (local entity) with an Id that references Invoice.Id (server entity).

The Is AutoNumber is set differently though..


Hello Rob,

This is a mistery for me.
The AutoNumber is set automatically when you change the type of the PK.

If you set to LocalEntity Identifier, it will be changed (and locked) to be NO autonumber.
If you set to ServerEntity Identifier, it will be changed (and locked) to be Yes, if value not set.

I'm not able to find a way of changing this behavior...

What version of SS and Server are you using?

Sorry. Found.

If your server entity has also a PK that is an attribute reference (FK to another entity), your local entiity will have its Autonumber set to No.

Cheers.

Hi Eduardo,

Both my server entities have PKs that are attribute references. The only difference is that the Expense entity refers to a server entity that is consumed from another application (see screenshot below).

I can't seem to find any documentation on this topic. Do you know if any exists?



Solution

Hi Rob,

This is what I tried to explain.
When the Server Entity has an Identifier that is also a Foreign Key (like in your Expense), the effect is the same. The local entity that has an ID to the server action will also be mandatory and will also need you to manually define the ID when creating a local record.

Cheers.

Solution

Hi Eduardo,

thanks for your explanation. The only thing I don't understand yet is why LocalInvoice.Id is an AutoNumber. If I understand your explanation correctly, this should also not be an AutoNumber since Invoice.Id is an Expense Identifier..

EDIT

I think I have replicated it. I must have created the LocalInvoice entity before I changed the datatype of the Invoice.Id attribute to Expense Identifier. So the LocalInvoice.Id Autonumber propery was set to 'Yes, if value not set'. When I changed the LocalInvoice.Id, this was not changed.

Cool :)