Header 1:M Detail (Detail is a loop inside Header Document)
Detail has 10 Line Item Type (program goes 10 times inside loop), based on this Line Item type I need to extract the $ amount (another field) at Detail level, sum up the $ amounts for all line items and then map it to header Level Total $ amount.
I know couple of options, store the $ amount in a 10 variables and them sum it up inside Detail loop 9 times using add built in service.
Write a java code to add the sum.
I am looking for the Best Practise recommended by webMethods.
Any suggestions!
You can build this standard logic in a flowservice itself.Here it is if worth
Before entering in the loop initialize a variable eg:total_lineAmount=0 and inside your loop depending on your LineItemType extract $amount.
Invoke addInts map total_lineAmount to num1,$amount to num2 and map output value to total_lineAmount.Once your loop iteration is done you will have sum of all lineitems amount in total_lineAmount.Finally map it to Header total amount.
Remember please dont drop total_lineAmount variable inside the loop it will hold its previous value in the pipeline to sum lineitem amounts.
Sounds like an interview question to me. If so, my advice is not to read any documentation, work any examples or actually learn the product first. Just wing it. I’m sure it will be OK.
Sorry for the misunderstanding. We’ve had way too many questions here lately fishing for answers to interview or cert exam questions without willingness to do any real work first. I’ll take a sedative and back away a bit.
A best practice would be to not use a java service to do this.