Monday, November 19, 2012

create a new row when there are no Records in View Object. ADF BC

Hi,

This is a quick post to show a way of creating a new row when there no records retrieved from a query in a view object.

in other words,
we want to create a record every time the view object does not return any data..

you can download the example from the following repository:
InsertRowWhenNoRecordExist
https://github.com/mox8iro/ADF-SamplesR2.git

In this example, we are going to have a master detail association between Countries and Locations.
This is from the HR schema.

So, in this case, we want to navigate through Countries and see the locations of every country.
In case there is no location for a country, we want to create a record and have it ready for data entry.

This solution is quite simple.

all we have to do is override the executeQueryForCollection method in the Locations View Object.


As you can see, we check if there is not any row in the view object, right after the queryExecution.
we choose to check if the first() method returns null. Of course there are other ways to achieve the same thing. It really depends on the case.

if the vo has no rows, we create a new row, insert it and make it current.



And thats it. as simple as it gets.

you can download the example from the following repository:


InsertRowWhenNoRecordExist
https://github.com/mox8iro/ADF-SamplesR2.git

Regards,


No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...