Auto fill input field in based on Data Provider when create

Posted by Lusien Lozanov on 10-Feb-2017 04:53

Hello guys,
I made an application with Kendo UI Builder.

Identity of records is guaranteed by ClientId like you can see on the picture.

Creating a new record is awful becouse of everytime writing a new ClintID by hand and merge it with current data every time when you want to create a record.

Is there a way to auto-fill this field with (biggest ClientId from my Data Provider)+1

All Replies

Posted by egarcia on 10-Feb-2017 05:52

Hello,

The most common approach to handle ID fields that need to be incremented, is to set the value of the ID field using a database sequence from a DB CREATE trigger.

You would need to set the skip-list variable in your Business Entity so that the value received in the request would not override the value set in the CREATE trigger.

You can disable the ID field on the screen.

When the new record is saved to the backend, the record is returned with the updated ID field.

Please let me know if you need additional information.

I hope this helps,

Edsel

Posted by Lusien Lozanov on 13-Feb-2017 02:42

I understand the logic but cant implement this with ABL Business Entity. I think i made such a little mistake but still not working.

I will be really thankful if you help me with ABL implementation.

Regards,

Lusi.

Posted by egarcia on 13-Feb-2017 05:39

Hello Lusi,

I am glad to help. Here is more information.

Your database trigger create would look like $DLC/sports2000trgs/crcust.p:

   TRIGGER PROCEDURE FOR Create OF Customer.

   /* Automatically Increment Customer Number using NextCustNum Sequence */

   ASSIGN Customer.CustNum = NEXT-VALUE(NextCustNum).

The setting of the skip-list variable would look like the following:

       cSkipListArray[1] = "CustNum".

What behavior are you seeing?

Are you getting an error message?

Are there any error messages in the agent log file?

You can debug this by looking at the HTTP request.

(You would see a PUT request with a call to the Submit method if you have Submit support in your Business Entity, otherwise, you would see a POST request to the resource URI.)

What is the value of the ID field that you get back in the HTTP request?

Are you getting the value that is being from the client? Then the issue is that the skip-list variable is not set correctly.

You could add a MESSAGE statement to write the value of the ID field in the CREATE trigger and also from the Business Entity after the code that creates the record. You can do a FOR EACH on the temp-table.

I hope this helps,

Edsel

Posted by Lusien Lozanov on 13-Feb-2017 05:58

Thanks Edsel,

I tried this but when i disable Id field on client side and try to add new record it tries to create record with id 0. And error message said 'can`t create record with existing id '

I think i dont disable the field correctly because it is used to send default Id like - 0

Posted by egarcia on 13-Feb-2017 07:11

Hello Lusi,

Thank you for mentioning about the error message.

There are two things that you may need to fix/change here.

1)

I would suggest to make sure that the database trigger is working correctly.

The reason that you are getting the error message seems to be because the table already has a record with ID = 0 (this might be ok with you depending on your DB design) and the new ID value is not.

You can quickly test using using a program that performs CREATE and updates the fields.

Example:

   CREATE Customer.

   UPDATE CustNum Name.

The CREATE trigger must be in the PROPATH so that the ABL can run it.

2)

Also, you may need to change the temp-table definition used by the Business Entity to either initialize the ID field with ? (unknown value - this can be done in the Data Dictionary as well) or remove the UNIQUE test for the index.

If you remove the UNIQUE test for the index, the validation will not be performed when the temp-table is set but when the record is saved to the actual database table.

Please let me know how it goes.

This thread is closed