I believe the lines uses the kDisplay index so you should actually be getting the last 6 characters instead. What you have is going to get you part of the LineSeqNo.
Original Message:
Sent: 05-23-2025 19:07
From: Phil McIntosh
Subject: Editing SO or PO lines from BOI app
@David Speck II Thank you!
For anyone finding this thread in a time capsule:
sTempKey2 = (string)sage_detail.InvokeMethod("sGetKeyPadded");
sTempKey = sTempKey2.Substring(7, 6); //to give data to match with the LineKey supplied in the JSON call
------------------------------
Phil McIntosh
Friendly Systems
------------------------------
Original Message:
Sent: 05-23-2025 16:55
From: David Speck II
Subject: Editing SO or PO lines from BOI app
GetKeyPadded returns a string but you still have (int) after "retval = ".
------------------------------
David Speck II
Blytheco LLC
Original Message:
Sent: 05-23-2025 14:08
From: Phil McIntosh
Subject: Editing SO or PO lines from BOI app
The first EditState value is for the lines object and is before calling MoveFirst(). I checked the header object EditState and it = 1.
Added in:
object[] parms = null;
parms = new object[1];
retval = (int)sage_detail.InvokeMethod("sGetKeyPadded", parms);
which gives "Exception has been thrown by the target of an invocation."
same for InvokeMethodByRef
------------------------------
Phil McIntosh
Friendly Systems
Original Message:
Sent: 05-21-2025 11:29
From: David Speck II
Subject: Editing SO or PO lines from BOI app
Since this is an external script, you'll have to prefix the method names with their expected returned value type, GetKey and GetKeyPadded return strings so they should be prefixed with "s". Whereas EditLine returns a number so it should be prefixed with "n". Since you have to wrap these method calls in the InvokeMethod function, I think you will have to separate the GetKeyPadded and EditLine methods on to their own lines so you can first return the full detail key into a string variable and pass it to the EditLine method. I think you would have to mimic what you are doing for your other method calls.
In your variable output, you list two instances of EditState, the first being 0, if this is the header's edit state, then I would suspect that the header is failing to set and so it isn't loading any lines. You could output the result of the header's GetKey method to see if it matches the PO number you tried to use in the SetKeyValue method. Something I like to do prior to calling any method that could possibly fail is to reset the object's LastErrorNum and LastErrorMsg properties, then call the method while capturing its returned value. You can then output the returned value, along with the LastErrorNum and LastErrorMsg property values to see if it was successful and if not, LastErrorNum and LastErrorMsg should give you some insight into why it failed. Keep in mind that warnings are also stored in these two properties and the business objects do not natively reset or clear them, they just continue to overwrite them with new values when a warning or failure situation occurs, this is why I manually reset them before the calling method I want to check, otherwise they could still contain previous values/messages.
------------------------------
David Speck II
Blytheco LLC
Original Message:
Sent: 05-19-2025 15:52
From: Phil McIntosh
Subject: Editing SO or PO lines from BOI app
@David Speck II - Finally got back to this. Here are the ersults:
EditState = 0
MoveFirst returns true (1)
EditState = 1
BOF = 1
EOF = 0
retval = (int)sage_detail.InvokeMethod("nGetValue", "LineKey$", sTempKey);
retVal = 1, sTempKey = "" //how is this possible??
MoveNext returns true (1)
BOF = 0
EOF = 0
I tried adding in oLines.EditLine(oLines.GetKeyPadded()) translated to c# as:
retval = (int)sage_detail.EditLine(sage_detail.GetKeyPadded()); gets:
'DispatchObject' does not contain a definition for 'EditLine' and no accessible extension method 'EditLine' accepting a first argument of type 'DispatchObject' could be found (are you missing a using directive or an assembly reference?)
'DispatchObject' does not contain a definition for 'GetKeyPadded' and no accessible extension method 'GetKeyPadded' accepting a first argument of type 'DispatchObject' could be found (are you missing a using directive or an assembly reference?) FS100API C:\Sage\FS100API\Controllers\PurchaseOrderController.cs 192
Do you have a working C# translation of that?
Phil
------------------------------
Phil McIntosh
Friendly Systems
Original Message:
Sent: 05-11-2025 09:10
From: David Speck II
Subject: Editing SO or PO lines from BOI app
Is the returned value from SetKey indicating that it is successful?
Typically, before I start a loop through the details, I do a check using the lines' GetRecordCount("Main") method, I then use the lines' MoveFirst, and then evaluate the lines' BoF and EoF properties, if they are both not True, I then start the loop.
In your case, I would check the value returned by lines' GetKey() method and the EditState property while in the loop and see what they are.
I think at one point, I did encounter a weird lines issue where using MoveFirst/MoveNext didn't set the line record into an editable state as expected and I had to use oLines.EditLine(oLines.GetKeyPadded()) before interacting with the line. Check the return value as well so you know what it is doing.
------------------------------
David Speck II
Blytheco LLC
Original Message:
Sent: 05-11-2025 08:52
From: Phil McIntosh
Subject: Editing SO or PO lines from BOI app
@David Speck II - there is a SetKey at the header level, I just didn't include it in the snippet.
if (dt.Columns.Contains("PurchaseOrderNo$")){ sOrder = dt.Rows[i]["PurchaseOrderNo$"].ToString();}retval = (int)sage.InvokeMethod("nSetKeyValue", "PurchaseOrderNo$", sOrder);retval = (int)sage.InvokeMethod("nSetKey");
------------------------------
Phil McIntosh
Friendly Systems
Original Message:
Sent: 05-11-2025 08:32
From: David Speck II
Subject: Editing SO or PO lines from BOI app
I don't see a SetKey at the header level so the lines object may not be loading records. You could try returning the lines' GetKey() method into a variable and see if it contains anything but if you have the PO #, you should be using the header's SetKey on it before you attempt to interact with the lines object. Since the LineKey value is only unique to each header key, you can't rely on just the LineKey value to find a specific line record out of all of the records in the detail table, you also have to use the PO #.
------------------------------
David Speck II
Blytheco LLC