Skip to Content
avatar image
Former Member

Validate record if it already exist when creating in SAPUI5

Hello Experts,

I'm trying to set up a validation if the certain key already exist from the database when creating a new record in Fiori.

I've already tried the this below:

1.Do a datamodel.read before datamodel.create

  • the problem with this is that when i try to input and save a record e.g "Key1" and then try to re-input it, it is always recognized as a non-existent record. This means that it still tries to process the save function eventhough its not being saved due to duplicate key in the database table

2.Set a result output in the RFC FM whenever I do a select statement to determine if the record already exist and check in the datamodel.create for the output result in the odata structure

  • problem is that the output is not being seen in the odata structure

Need your help on this. Thank you

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Mar 07, 2017 at 06:21 AM

    during the creation, if the key existed, just raise exception...that's it. your error function will be called.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 07, 2017 at 06:07 AM

    Hello Jastin,

    You can include select and insert operation in single FM and call this FM (odata service)while calling odata.create() method. Raise an exception in FM if record already exists else throw a success message. By this approach you can avoid odata.read().

    Regards,

    Gowrinath

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 07, 2017 at 01:18 PM

    Hello Jastin,

    Always write a COMMIT WORK statement after every create operation ( Insert Record ) and perform read operation on the same record then confirm with a success message. Now if you do read operation, definitely your validation will works.

    Some times there will be cases we might be reading the records before it was created in tables. In such cases this issue will occurs.

    --

    Thanks & Regards

    Abdul Bash Shaik

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 07, 2017 at 10:05 PM

    Thank you very much for the answers. Raising an exception works!

    Add comment
    10|10000 characters needed characters exceeded