cancel
Showing results for 
Search instead for 
Did you mean: 

7.1: how to create a new record in the client

Former Member
0 Kudos

This is a question for NW Mobile 7.1

Dear all,

in our mobile app we want to add a new record. In the class RNM71 we learned how to display existing records and to modifiy them, but there is no example how to create a new one.

I could not find anything in the docs ...

Any ideas?

Thanks, Andre

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Stefan,

thanks a lot. So we have to bind the new instance to our context. (Some code example would be great )

I will try it out as soon as possible. Unfortunately I messed up my NWDS installation. It looks like creating and deleting services and data models can destroy some internal files. Luckily I am running NWDS in a VM and can back out to a certain point.

I will let you know.

Cheers, Andre

stefan_henke
Contributor
0 Kudos

Hi Andre,

if you created a new node in your view context, you can access it via the wdContext object in your view. Let´s assume you have a node called "Customer" which is mapped to a model class called "CustomerNode", then you can use the following coding:

CustomerNode cust = model.createCustomer(...);

......

wdContext.nodeCustomer().bind(Collections.singleton(cust));

....

This will bind the content of the cust object to the context and update all UI elements which are bound to the context node.

Regarding the issues with the corrupt workspace, could you let me know which steps exactly caused this corruption? And which version you are exactly using (SP, trial version?, etc).

Regards,

Stefan

jan_fetzer
Advisor
Advisor
0 Kudos

Hi Andre,

the employee application packaged with NWM 7.1 Trial version and described at [https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/9140] [original link is broken] [original link is broken] [original link is broken]; has a create button exactly like the one you are planning. Please consult the application's code for details.

Bye, Jan

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Jan,

the set of examples in the above mentioned trial package is great. A lot to learn from. And many many many ... features that were never mentioned in the class

Thanks, Andre

stefan_henke
Contributor
0 Kudos

Hi,

for PDA, you can take a look at the sample described in the documentation:

http://help.sap.com/saphelp_nwmobile71/helpdata/en/45/f6ffc43aca34dde10000000a1553f7/content.htm

It should not be a problem to map this sample to your concrete case. In general, the procedure is to

1) get the model class instance using OcaRoot.getInstance().getModel(....);

2) Call the create method on the model class for the root node of the DO

3) Eventually create child nodes by calling the create methods on the root node object

4) commit the changes by calling OcaRoot.getInstance().commit();

For Laptop, it should work in a very similar way. I´m not that familiar with the laptop API. Let me come back to you with some more concrete ideas.

Regards,

Stefan

Former Member
0 Kudos

Hi Stefan,

I guess I forgot to describe the main problen in my question.

How do I bind such a new record to the UI?

I want to implement the functionality of a "NEW" button, which displays a data entry form. Clicking on the "SAVE" button should then persist the data.

In the UI I have to bind each data entry widget (like TextEdit) to a field in the context. How does that work with a new record?

Cheers, Andre

stefan_henke
Contributor
0 Kudos

Hi Andre,

in principle, you have to do the same:

1) Create a new node in the (view) context which is bound to the DO node class in the model you created

2) You can now create the DO node via API. After calling the create....() method, you have an object of the class for the DO node. This class you can directly use and bind to the context node using the .bind() method. Please make sure that you

changed the cardinality of the context node to 1..1. By default it is 0..n

Please let me know if this worked for you.

Regards,

Stefan

stefan_henke
Contributor
0 Kudos

Hi Andre,

are you talking about NW mobile 7.1 for pda or laptop? The answer would be different for these two topics.

Regards,

Stefan

Former Member
0 Kudos

Hi Stefan,

we are developing for PDAs ...

Cheers, Andre

Former Member
0 Kudos

Hi Stefan,

May i know the answer for laptop as well? thank you.

Regards,

Joan