cancel
Showing results for 
Search instead for 
Did you mean: 

MI 7.1: Node Instance Creation and Context Mapping

Former Member
0 Kudos

Hi everyone,

I am finding myself confused when creating new node instances on the client and using context mapping.

I will try to explain my scenario as best as possible.

1. Create a context node in the UI Component Controller and bind it to a Model

2. Create a context node in a View of the UI and map it to the context node of the controller

3. What I want to do next is create new instances of the node using the context of the view. I used create methods of the context and performed an OcaRoot.getInstance().commit(). However, my newly created instances are not saved in the local database. I figured that this should be possible. Although, I've typically witnessed this method of creating new instances:

newInvDoc = ((Mdcoff_zmm_invt_count_scModel)OcaRoot.getInstance().getModel (Mdcoff_zmm_invt_count_scModel.class)).createZmminvdocInvDocHdr();

Can it not be accomplished through the method I've described. To me it makes more sense. I have used my method to update node instaces and have been successful. Perhaps I'm missing something.

Thanks,

Alex

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks everyone for your answers.

I have another question if any of you could give me some help on. In this scenario, I have a data object with a Root node and a Child node (average scenario). I create a new instance of a root node with x number of child nodes and then the user saves the information (commits to local DB). However, I wanted the ability that if the user saved by mistake and needed to add an additional child that they could without creating a duplicate Root node.

When I tried this it did not work. I found that if I created a new data object node, commited and then added another new child node to it that I would get a mapping error from the DOE telling me it could not locate the node in the CDS table for an update/delete.

So my current solution is to allow a duplicate root node to be created if this scenario was to happen. Which I'm surprised works since I set the backend key fields. Should this not cause a duplicate entry error locally?

I just find it odd that once you commit a new node instance you cannot change it and keep it as a "create" message call to the DOE.

If it helps I'm using the SAP mobile client ..... not a custom one.

It would be great if someone could help clarify this.

Alex

former_member206242
Active Participant
0 Kudos

HI,

A message call for the DOE is generated after a COMMIT. In case its a first create then create message will be generated on commit. After the commit all subsequent modifications to the same record will result in a modify message...

Now regarding updating/adding a child a record already committed by mistake. At this point you can get the already created record from the node again or from the DB thru query and then add a child to the model of that nodel element.

This is a simple process and is relevant for any modifications. IF already the data is present in the node then using lead selection you can refer to the regard and change the bound context attributes and do a commit. The changes will be persisted and sent as a modify message to the DOE.

Duplicate record is not a scenario as on each create a fresh record in returned by client. The values for attributes can be duplicated but record duplication should not happen unless there is some DB or any other issue.

Regards,

Nipun

former_member53099
Participant
0 Kudos

hi

i such a case a duplicate instance should never be created. Even if a commit is made ...then a separate instance will be created with a separate 'synckey'

Its a very common requirement from users to create a new root instance and then add chidren to it later.

So when the root is created ..... an insert type of message is sent to DOE

Now when a new child is added to this root ..... an update of the root goes with the newly inserted child

In this case one just has to retrieve the root (to which the child has to be added), do the chenges and then just call 'commit' later.

Here is a code snippet of such a scenario

ROOT rt = wdContext.currentROOTElement().modelObject();

CHILD_ITEM item = rt.createNewCHILD_ITEMs();

rt.addToCHILD_ITEMs(item);

model.commit();

Hope this helps

Best Regards

Vaidehi

Former Member
0 Kudos

Hi Vaidehi

Thanks for the reply. I did attempt what you said. I had code to initially create a new header and add any childs at that time. It would then perform a commit. Then if the user wanted to add another child to it later, I would call up that header and add yet another child to it and perform a commit. However, the problem was when I attempted a sync. The update would cause an error because it said the DOE could not find the header instance to update. This is because the object only performs a create and the node instances are not stored on the DOE.

So I was thinking that I could only update a header with a new child if I allowed updates (basically a bapiwrapper create and modify). This meaning that I had to add all child nodes to the header before any commit is called. I also thought of either holding off a commit until they exited the program but I was afraid if something happened during that time and they'd lose everything.

Thanks,

Alex

Former Member
0 Kudos

Hi Vaidehi

Thanks for the reply. I did attempt what you said. I had code to initially create a new header and add any childs at that time. It would then perform a commit. Then if the user wanted to add another child to it later, I would call up that header and add yet another child to it and perform a commit. However, the problem was when I attempted a sync. The update would cause an error because it said the DOE could not find the header instance to update. This is because the object only performs a create and the node instances are not stored on the DOE.

So I was thinking that I could only update a header with a new child if I allowed updates (basically a bapiwrapper create and modify). This meaning that I had to add all child nodes to the header before any commit is called. I also thought of either holding off a commit until they exited the program but I was afraid if something happened during that time and they'd lose everything.

Thanks,

Alex

muhammed_nishad
Participant
0 Kudos

Hi Alex,

check message monitoring after sync . check for the items, and find your updation of item in message monitoring . try restart the message from there. if if again fails, check the wrapper.

Regards,

Muhammed Nishad J

www. applexus.com

Former Member
0 Kudos

Hi Muhammed,

I've checked the message monitoring before. That is how I knew I was receiving the error. So technically this was the scenario:

1. Header and child creation and then a COMMIT is performed

2. Then before syncing another child is added to the already existing header and another COMMIT is performed

3. Now I sync

The error that the DOE reveals is the following:

Error Source: DOE

Service Name: KEYMAP_SERVICE_BV

Message: Cannot update/delete object that does not exist in the CDS; node 'INV_DOC_HDR'

So my guess is because I do not keep the created instances locally on the DOE it cannot "update" the header. So either I call commit only once for a header on the device before syncing or possibly start keeping the instances locally on the DOE.

This is my way of thinking but perhaps i'm still wrong.

Alex

Former Member
0 Kudos

Hi Muhammed,

I've checked the message monitoring before. That is how I knew I was receiving the error. So technically this was the scenario:

1. Header and child creation and then a COMMIT is performed

2. Then before syncing another child is added to the already existing header and another COMMIT is performed

3. Now I sync

The error that the DOE reveals is the following:

Error Source: DOE

Service Name: KEYMAP_SERVICE_BV

Message: Cannot update/delete object that does not exist in the CDS; node 'INV_DOC_HDR'

So my guess is because I do not keep the created instances locally on the DOE it cannot "update" the header. So either I call commit only once for a header on the device before syncing or possibly start keeping the instances locally on the DOE.

This is my way of thinking but perhaps i'm still wrong.

Alex

muhammed_nishad
Participant
0 Kudos

HI Alex,

Make sure that all the Backend Key fields marked in the middleware header node are export parameters of the Create wrapper. Also set all the key fields in UI before OCA commit.

Regards,

Muhammed Nishad J

www.applexus.com

Answers (4)

Answers (4)

muhammed_nishad
Participant
0 Kudos

Hi,

PDA solution

If you requirement is to add multiple child to a root node. you need to get the parent node and try adding the child

Header = ((servicecompModel) OcaRoot.getInstance().getModel(

ServicecompModel.class))

.getDoOrderHeader(sHeaderSyncKey);

ItemToUpdate = Header.createNewItem();

ItemToUpdate.setField("TEST");

Header.addToNewItem(ItemToUpdate);

OcaRoot.getInstance().commit();

Once this is done the new item is created, with the update flag 'I"

Laptop Solution

Header = wdContext.nodeitem.currentnodeitemOutputElement()

.modelObject();

Item = Header .createNewITEMs();

Item.setD_CODE("Code");

Header.addToITEMs(Item);

model.commit();

Once this is done the new item is created, with the update flag 'I"

Regards,

Muhammed Nishad J

www.applexus.com

muhammed_nishad
Participant
0 Kudos

Hi,

If you are using LAPTOP perspective, you can refer the blog

[Building Queries in Netweaver Mobile 7.1 - Laptop Perspective|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/16797] [original link is broken] [original link is broken] [original link is broken];

[Consuming Queries in Netweaver Mobile 7.1 - Laptop Perspective|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/16991] [original link is broken] [original link is broken] [original link is broken];

Regards,

Muhammed Nishad J

Applexus

Former Member
0 Kudos

Hi Alex,

If you are looking for an OCA application you can refer the below link. Creating context nodes, context mapping, generating test data are clearly mentioned in the document.

http://www.sdn.sap.com/irj/scn/index;jsessionid=(J2EE3417800)ID0755671850DB21029097249755913786End?r...

Hope this will help you.

Regards,

Dhanya

Edited by: Dhanya K Moni on Dec 11, 2009 10:56 AM

former_member206242
Active Participant
0 Kudos

Hi,

To create a new record/element in the context node, you will have to create one at the model first and then bind it to the node pointing to the Data Object.

You can also do creation in service component and expose thru a custom operation.

E.g

newInvDoc = ((Mdcoff_zmm_invt_count_scModel)OcaRoot.getInstance().getModel (Mdcoff_zmm_invt_count_scModel.class)).createZmminvdocInvDocHdr();

<DONODE>.bind(Collections.Singleton(newInvDoc);

<DONODE>.setLeadSelection(0);

<DONODE>.getCurrent<ElementName>Element()

// Add the values for this element attributes (node attributes)

Call Commit.

(Pls note that syntax can be wrong, pls check at code time).

Regards,

Nipun