on 05-23-2006 12:08 AM
Hi there, due to an enormous amount of time spent on this issue, I thought I would share how to use the SetCurrentLine method as posted to me by SAP support:
It seems very cumbersome, as I have now to do an extra Recorset look up to get all the lines if I want to get the correct index - but at least it works (hopefully).
Daniel
SUPPORTS MESSAGE ****
the way the SetCurrentLine works is as following:
You do not have to use neither the LineNum nor the VisOrder as your
parameterfor the setCurrentLine method.
The system will use the corresponding index (starting at zero)linked to
that line when running a query on the database and sorting the lines by
LineNum.
#,,DocEntry,, Item ,,LineNum,,Price,,VisOrder
1,,11669,, A1001,,,, 600,00,,
2,,11669,, A1003,,2,, 3,00,, 2
3,,11669,, A1005,,3,, 600,00,,1
See example above, that is the result of querying the database on that
sales order and sorting by LineNum.
The order in which the items are displayed in the application is based
on the VisOrder. In this example items are displayed A1001, A1005 amd
A1003.
In order to update Item A1005 I will need to create a recordset, query
the database and then loop the recordset to find the corresponding item
and then use that index from the recordset to set the value for the
SetCurrentLine method. In the example above index 0 from recordset
points at item A1001, index 1 points at item A1003 and index 2 points at
A1005 so your code should use setCurrentLine(2) to update item A1005.
If you try to use LineNum (3 in this case) you will get an error message
as index 3 does not exist in the recordset collection ( only 3 items
with indexes 0,1 and 2). If you use visOrder 1(for item A1005) then the
system will update item A1003 as 1 is the index for A1003 in the
recordset.
END OF SUPPORTS MESSAGE ********
We have had many similar issues with this setcurrentline issue. Which version of SBO are you using?
I believe this was supposed to be addressed in one of the latest patch releases for 2004.
In the method support told you to use what would happen if you had multiple line items with the same item code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Curtis, yes the lastest patch for 2004 was supposed to have addressed this, but on documents which are heavily modified, (lines inserted at the start, middle etc and lines deleted) the document would not always select the correct line with SetCurrentLine.
I have tested the way support says to use it, and while it is very cumbersome, it works 100% of the time which is what I needed...
Cheers,
Daniel
Hi Curtis,
It is fine because you can test for the LineNum when you traverse through the rs.
ie, I know that I want db LineNum 5, so I get the recordset with all the lines (ordered by LineNum) then iterate through them, and the index where I find LineNum 5 I then use SetCurrentLine against that index...
- does that make sense?
Thanks Daniel,
THat sort of makes sense.
If I have a recordset of orders that I want to update and I want to update the line items.
I start looping over my recordset of orders and then how do I update the line items using setCurrentLine to ensure the correct line items are updated?
Do you have some code you can share?
/* get all the lines so we know what is the line index to use for setcurrentline */
SAPbobsCOM.Recordset linesRs = (SAPbobsCOM.Recordset)_SboCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
linesRs.DoQuery(string.Format("select LineNum from {0} where DocEntry = {1} order by LineNum", tableName, docEntry));
int lineIndex = 0;
while(!linesRs.EoF)
{
if((int)linesRs.Fields.Item("LineNum").Value == lineNumber)
break;
lineIndex ++;
linesRs.MoveNext();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(linesRs);
doc.Lines.SetCurrentLine(lineIndex);
Hi Curtis,
Your situation sounds a little different to mine, in that I know the LinNum of the documentline that I need to update - that is what the lineNumber variable is...
To update all the rows, I guess you would just iterate through all the lines sequencially (ie starting at 0 and ending at document.lines.count:
for(int i = 0; i < doc.Lines.Count; i++)
{
doc.Lines.SetCurrentLine(i);
// do your thing here...
}
How do you know what lines you want to update??
Dan
Thanks for sharing this, Daniel!
I think there's a SAP Support note as well.
I will update this reply with it's number when I found it.
Regards,
Frank
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
110 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.