Skip to Content
0

Validate record if it already exist when creating in SAPUI5

Mar 07, 2017 at 05:51 AM

95

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Jun Wu Mar 07, 2017 at 06:21 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Gowrinath Gundu Mar 07, 2017 at 06:07 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
AbdulBasha Shaik Mar 07, 2017 at 01:18 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Jastin Coronado Mar 07, 2017 at 10:05 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded