cancel
Showing results for 
Search instead for 
Did you mean: 

Update an Entity in WD Application

Former Member
0 Kudos

Hi All,

in my Web Dynpro Application I can create an entity in an existing entity service. I can do that with the following code:

AChangeDescriptionDB db = ChangeDescriptionDBServiceProxy.create();		
db.setProcessID(processID);
db.setTitle(actualTitle);
db.setType(wdContext.currentContextElement().getType() ); 
...
db.getAspect().sendChanges();

But how can I update or delete an entity?

Should be possible, but I dont found out a way?

Thanks in advance

Steve

View Entire Topic
Austin
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Steve,

The update is performed like a create, except that you already have the Entity from a findBy() or through relationship navigation.

Example:

db.set..

db.set..

db.getAspect().sendChanges();

The delete is performed by calling removeAspectRow().

Example:

db.getAspect().removeAspectRow(db);

db.getAspect().sendChanges();

Regards,

Austin.

Former Member
0 Kudos

Hi Austin,

cna you post me the code for getting the db instance with a findBy()-method.

For me its not possible, cause findby() returns only IAspects.

Bye & Thanks

Steve

0 Kudos

Hi Austin,

The code to get the aspect instance using findBy is as follows:

IAspect tempAspect = ChangeDescriptionDBServiceProxy.findBy(arg0, arg1,...);

If(tempAspect != null){

Iterator itr = tempAspect.iterator();

while(itr.hasNext())

AChangeDescriptionDB db = (AChangeDescriptionDB) itr.next();

.......

}

You can use any other method for looping if you want to retrieve the entire list.

If you want to retrieve a specific element from the available rows you can directly retrieve it as follows:

AChangeDescriptionDB db = (AChangeDescriptionDB)tempAspect.getAspectRow(0);

Hope this helps.

Regards,

Suparna

Former Member
0 Kudos

Hi Suparna and Austin,

thanks that works fine.

Is there another solution when searching within a findBy-method after a key-attribut, a more effective way without a iterator (because in this case I need no iterator, which goes over a list of aspects).

Thanks Steve

0 Kudos

Hi Steve,

If your query returns a single result you can use the second line of code that I have mentioned in my reply instead of using the iterator part of 1st code example.

In case your query is something else you can explain it. I can suggest you the code.

Regards,

Suparna

Former Member
0 Kudos

Hi Suparna,

I work with your second solution.

But the down-cast you mentioned is not working (or possible), it raised an errorevent.

AChangeDescriptionDB db = (AChangeDescriptionDB) itr.next();
AChangeDescriptionDB db = (AChangeDescriptionDB)tempAspect.getAspectRow(0);

In my mind I thought of an solution with a findby-method like findByUniqueKey(uniquekey) and then I got only one aspect row.

But its important cause my application is working now, its only for better code understanding.

Bye Steve

0 Kudos

Hi Steve,

Which code are you using? As far as I can understand from your reply, its

code line 1: <i>IAspect tempAspect = ChangeDescriptionDBServiceProxy.findUniqueKey(uniqueKey);</i>

//This returns you only one record. So you do not use the iterator but directly get the first row as follows

code line 2:

<i>if(tempAspect!=null){

AChangeDescriptionDB db = (AChangeDescriptionDB) tempAspect.get(0);

....

}</i>

Can you please confirm if this code line 2 where you are typecasting is giving you the error? I am confused because you have mentioned 2 codes from 2 different scenarios, itr.next() for list and .getAspectRow(0) for single record. Or is it like both these cases throw error when you use them separately?

Here I have to mention that you must have added public part default of DC tc/col/api (compartment

SAP_JTECHS) in order to use the code for "IAspect".

Please let me know the error. Also, please mention the version of NW2004s that you are using.

Regards,

Suparna

Message was edited by: Suparna Deb

Former Member
0 Kudos

Hi Suparna,

sorry for the delay.

First i cannot find the method findByUniqueKey(uniqueKey).

Your question:

I used the two codelines seperatly for testing out.

AChangeDescriptionDB row = (AChangeDescriptionDB)aspitr.next();

is not working, raises an event.

AChangeDescriptionDB db = (AChangeDescriptionDB) asp.get(0);

works fine, sorry my fault.

Thanks STeve