cancel
Showing results for 
Search instead for 
Did you mean: 

Updating a nested collection in agentry

Former Member
0 Kudos

Hi;

I am working on customising  Work Manager 6.0 in Agentry 6.1.3. I have a new object zInspectionOrder, which contains a collection of InspectionPoints, which in turn contains a collection of InspectionTasks. This fetches and shows on the device. What I am working on now is the updating/Editing of the InspectionTasks from the device to the SAP backend. Please kindly advise as to how I would go about posting the edited InspectionTasks . How many transactions do I need and what type, currently I only have an edit transaction on the InspectionTask object, but my Java code gives a Java Business Logic Exception when I transmit with an edited InspectionTask and on the Java side, I have created a new update steplet, stephandler and bapi class and have inserted the setProperties method for transactions in the InspectionTask object. Am I going wrong somewhere, please guide and advise.

Much appreciated!.

Thanks and Regards;

Sizo Ndlovu

Accepted Solutions (0)

Answers (1)

Answers (1)

jason_latko
Advisor
Advisor
0 Kudos

Sizo,

No, you are on the right track.  You should just need a single transaction that edits your object and the subsequent java tied to that transaction.  Have you tried debugging the new java to see where the problem is?  What is the error you are receiving?

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Hi Jason;

I managed to get the error resolved, there was issues with my java code. Now, the data does get to the SAP backend, but it is getting updated 1 Inspection Task at a time, even for inspection tasks within the same Inspection order. Please advise, how could I possibly tie all inspection tasks belonging to the same inspection order together and send this as a table to the SAP backend instead of sending individual inspection tasks, 1 at a time. I have tried putting the data to be updated in a table, but it seems to be putting 1 Inspection Task per table and the next one in a different table again. Please advise how best I could archieve updating all inspection tasks for 1 inspection order at one goal in a table?

Much appreciated!

Sizo Ndlovu

jason_latko
Advisor
Advisor
0 Kudos

Sizo,

This is called transaction bundling.  One way to approach this is to always run a silent inspection edit transaction that passes up all inspection properties including the inspection tasks collection to your java steplet.  Run this in any action after any transaction that affects an inspection task: Adds or Edits.  Make sure the task step is first applied.  When I say silent transaction, I mean one that does not use a screenset and requires no interaction with the user.  Do not tie any update java steps to the inspection task transactions, only to the final inspection edit.  Also, use transaction merging on the silent edit so only one of these per inspection will get sent up, not multiple edits.  Now in the java, you will have access to all the inspection tasks at once.  Loop over these to populate all the inspection task rows in the BAPI table to post the changes all at once.  Refer to work manager or service manager code to see how the looping works.

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Hi Jason;

Thanks for the direction, I have implemented the transactions as per your guidance above. I have created an edit transaction for Inspection order object, with all the properties of inspections orders including inspection points. Quick quiestion though, how do I then maintain Inspection Tasks as a property within Inspection Orders, as these are a collection within Inspection Points, would only adding Inspection Points collection property to Inspection order transaction suffice or I would need to add the Inspection task collection property as a seperate property within the inspection orders, the same way that I do with the Inspection Points collection. Please kindly see below what I currently have:

Is the above in order, because the Inspection Tasks are contained within the Inspection Points? If not, how would I then go about maintaining Inspection Tasks within  Inspection Points, do I then need another transaction for Inspection Points Edit? I have also removed the update step that calls the java steplet from the Characteristic edit (Inspection Task edit)and attached it to the new InspectionOrderEdit transaction, please see below:

But now, when I test by running the transmit after editing a couple of inspection tasks, the java steplet does not seem to get called at all. What is it that I am not doing or doing wrong. the synchronisation/transmit image does not even show on the device after doing some editing.

I would very much appreciate your help!

Thanks and Regards;

Sizo Ndlovu

jason_latko
Advisor
Advisor
0 Kudos

Sizo,

Just adding inspection points collection would be fine.  You can still get at all the child collections under an inspection point from the java:

transaction.InspectionPoints(x).InspectionTask(y).property

These are zero based arrays, so the first object in both collections would use zero as the array index.

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Hi Jason;

Thank you for the Java pointers, but before we get to the Java, my java steplet does not seem to be getting called after an edit of Inspection Tasks and transmitting. I have put the java steplet call on the update step on the InspectionOrderEdit transaction and removed it from the InspectionTaskEdit transaction as you suggested. Before, when I had the java steplet call on the InspectionTaskEdit update step, the steplet was being called after editing and while doing a transmit. Is there something that I am missing?

Thanks and Regards;

Sizo Ndlovu

Former Member
0 Kudos

Ok, the Java steplet is getting called now. I hadn't specified the target object on the Inspection Order Edit transaction.

Regards;

Sizo Ndlovu

Former Member
0 Kudos

Hi Jason;

I get the following error when Implementing the Java code:

*** Unexpected character in transaction.InspectionPointstransaction.InspectionPoints(0).InspectionTask(0).CONFIRM_NO>>

My code is as follows:

Please advise.

Thanks and Regards;

Sizo Ndlovu

Former Member
0 Kudos

I finally got this working, it was a Java syntax error on my side, I just had to use the prefix string, thanks a lot Jason:

One more final thing though Jason? Is there a syntax that I can use for determining the number of Inspection Tasks that have been edited by the user, per Inspection Order, so I can use this to loop through the edited number of Tasks?

Much appreciated!

Thanks and Regards;

Sizo Ndlovu

jason_latko
Advisor
Advisor
0 Kudos

Sizo,

Yes, use some code like below to get the collection size from the transaction:

int sz = Integer.parseInt(u.eval("<<size transaction.ConfirmationItems>>"));

for (int i=0; i<sz; i++) {

    //Do the work here

}

Above, u is the user instance.  This may be different depending on your class.

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Hi Jason;


String numEdits = _user.eval("<<size transaction.InspectionTasks>>");


I get the error "For input string: "no flunky found transaction.InspectionTasks SpinDoc""


Secondly, I can hard code this value temporarily, but always, irregardless of how many tasks I have edited, I seem to always get 2 records in the BAPI table at the backend, even when I have edited several tasks belonging to different Inspection orders. Please kindly see my code below:


This code is sitting in the bapi class for update

Thanks and Regards;

Sizo Ndlovu

jason_latko
Advisor
Advisor
0 Kudos

Sizo,

When getting the size, you need to reference the collection the way you set up your prefix:

("<<size transaction.InspectionTasks>>"); is not a valid collection.  You need to specify the full path to the data.

Your code snipet is incorrect.  You need two loops.  The outer loop needs to loop over the InspectionPoints collection:

<<size transaction.InspectionPoints>>

Then an inner loop needs to loop over the InspectionTasks collection inside the current InspectionPoint.  Below uses i as the array index from the first loop:

<size transaction.InspectionPoints(i).InspectionTasks>>.

Your incorrect single loop in the snipet is going to send up point(0).task(0), then point(1).task(1), point(2).task(2), etc..

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Awesome Jason, spot on. Just the way you have said it. You are a genius!!

Thanks!