Sage 100

 View Only
Expand all | Collapse all

Editing SO or PO lines from BOI app

  • 1.  Editing SO or PO lines from BOI app

    Posted 05-09-2025 17:31

    For editing lines of an existing order, I am looping through the liens object to retrieve the LineKey, compare that to the LineKey provided in the calling JSON, and then SetKey to apply the edits.  Code snippets follow.  The problem is that the line of code that retrieves the LineKey form the records in the loop returns 1, but the variable sTempKey is not populated.  Any idea why?

    using DispatchObject sage = new DispatchObject(pvx.InvokeMethod("NewObject", "PO_PurchaseOrder_bus", oSS.GetObject()));
    using DispatchObject sage_detail = new DispatchObject(sage.GetProperty("oLines"));
    if (dt.Columns.Contains("LineKey$"))
    {
        sLineKey = dt.Rows[i]["LineKey$"].ToString();
        'there is avlue here
    }
    ...
    if (sLineKey != "")
    {
        {
            //loop through lines to find match and get actual key
            retval = (int)sage_detail.InvokeMethod("nMoveFirst");
            'retval here is 1
            do
            {           
                retval = (int)sage_detail.InvokeMethod("nGetValue", "LineKey$", sTempKey);
                'retval is 1, but sTempKey = "" - WHY??



    ------------------------------
    Phil McIntosh
    Friendly Systems
    ------------------------------


  • 2.  RE: Editing SO or PO lines from BOI app

    Posted 05-11-2025 08:32

    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
    ------------------------------



  • 3.  RE: Editing SO or PO lines from BOI app

    Posted 05-11-2025 08:52

    @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
    ------------------------------



  • 4.  RE: Editing SO or PO lines from BOI app

    Posted 05-11-2025 09:11

    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
    ------------------------------



  • 5.  RE: Editing SO or PO lines from BOI app

    Posted 05-19-2025 15:52
    Edited by Phil McIntosh 05-19-2025 16:01

    @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
    ------------------------------



  • 6.  RE: Editing SO or PO lines from BOI app

    Posted 05-20-2025 08:42

    I'm not a c# guy at all, but my two dumb thoughts:

    Is sTempKey initialized explicitly as a string before hand (sTempKey = '') 

    When I use PowerShell with GetValue, I need to prefix [ref] in front of the receiving variable to force it by reference:  

    $r = $oUDT.nGetValue("UDF_EMAIL$",[ref] $udtEmail)

    Is there an equivalent in C#?



    ------------------------------
    Steve Iwanowski, NextStep Technology Advisors, aka DSD Lancaster PA ¯\_(ツ)_/¯
    ------------------------------



  • 7.  RE: Editing SO or PO lines from BOI app

    Posted 05-20-2025 10:58

    string sTempKey = "";

    is in there, declared as string and set to empty string.



    ------------------------------
    Phil McIntosh
    Friendly Systems
    ------------------------------



  • 8.  RE: Editing SO or PO lines from BOI app

    Posted 05-21-2025 11:29

    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
    ------------------------------



  • 9.  RE: Editing SO or PO lines from BOI app

    Posted 05-23-2025 14:09

    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
    ------------------------------



  • 10.  RE: Editing SO or PO lines from BOI app

    Posted 05-23-2025 16:55

    GetKeyPadded returns a string but you still have (int) after "retval = ".



    ------------------------------
    David Speck II
    Blytheco LLC
    ------------------------------



  • 11.  RE: Editing SO or PO lines from BOI app

    Posted 05-23-2025 19:07

    @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
    ------------------------------



  • 12.  RE: Editing SO or PO lines from BOI app

    Posted 05-23-2025 19:17

    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.



    ------------------------------
    David Speck II
    Blytheco LLC
    ------------------------------