Scripting

Expand all | Collapse all

BOI in C# nLogon line from Sage's samples seems to

Chris Mengerink

Chris Mengerink02-15-2018 17:43

Phil McIntosh

Phil McIntosh02-18-2018 09:52

  • 1.  BOI in C# nLogon line from Sage's samples seems to

    Posted 02-15-2018 14:46
    BOI in C# nLogon line from Sage's samples seems to want to pop up a login box, but I need a silent server app connection. In the Sage example: oSS.GetType().InvokeMember(""nLogon"", System.Reflection.BindingFlags.InvokeMethod, null, oSS, null); I tried: oSS.GetType().InvokeMember(""nLogon"", System.Reflection.BindingFlags.InvokeMethod, null, oSS, new object[] { app..Properties.Settings.Default.SageUser, app..Properties.Settings.Default.SagePW }); The properties do have correct values. Error is the extremely helpful ""Exception has been thrown by the target of an invocation"" Any ideas on what the correct syntax is?


  • 2.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-15-2018 15:03
    i'm not familiar with C# syntax so i'm a little confused reading your lines, when you are invoking nLogon, are you passing any parameters to nLogon? according to the File Layouts and Program Information, the Logon method does not take any parameters as it will set the user to the Default User,if you are trying to specify a user and password, you should be using the SetUser method.


  • 3.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-15-2018 15:05
    But here is some C# code I have from notes of how to use the dispatch object using (DispatchObject oSS = new DispatchObject(oScript.InvokeMethod(""NewObject"", ""SY_SESSION""))) { oSS.InvokeMethod(""nLogon""); oSS.InvokeMethod(""nSetUser"", MASUser, MASPassword); oSS.InvokeMethod(""nSetCompany"", MASCompany); oSS.InvokeMethod(""nSetModule"", ""S/O""); Not sure this helps?


  • 4.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-15-2018 15:08
    Looking back through a couple of my external scripts, I never used the Logon method, only the SetUser method as i have never tried to use the ""Default User"".


  • 5.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-15-2018 16:22
    Thanks @DavidSpeckII and @ChrisMengerink ! It is nSetUser that is needed. Weird how the syntax is so different from VB to C#. Normally the online translators between the two get really close, but in this case they are useless. @ChrisMengerink - does your example include setting the field values for a write? sDiv = dt.Rows[i][""ARDivisionNo$""].ToString(); object[] divObject = new object[] { ""ARDivisionNo$"",sDiv }; ar_cust_bus.GetType().InvokeMember(""nSetKeyValue"", System.Reflection.BindingFlags.InvokeMethod, null, oSS, divObject) is failing on the last line.


  • 6.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-15-2018 16:41
    @PhilMcIntosh , it might just be me but your C# looks overly complicated. Can you not just use ar_cust_bus.InvokeMethod(""nSetValue"", ""Column"", ""Value"")?


  • 7.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-15-2018 17:34
    Glad you suggested that. I had problems with the Dispatch Object example from Sage City, so I dropped back to the older really verbose example. Now that I solved the initial issue, the Dispatch Object method is much closer to the VB syntax.


  • 8.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-15-2018 17:43
    header example object[] curOrderNum = new object[] { ""SalesOrderNo$"" }; curOrderNum.SetValue(SalesOrderNo, 0); nReturn = (int)so_order.InvokeMethod(""NSetkey"", curOrderNum); nReturn = (int)so_order.InvokeMethod(""nSetValue"", ""ARDivisionNo$"", ""80""); nReturn = (int)so_order.InvokeMethod(""nSetValue"", ""CustomerNo$"", ""0140004""); nReturn = (int)so_order.InvokeMethod(""nSetValue"", ""OrderDate$"", created_at.ToString(""yyyyMMdd"")); detail lines example: DispatchObject so_detail = new DispatchObject(so_order.GetProperty(""oLines"")); nReturn = (int)so_detail.InvokeMethod(""nAddLine""); nReturn = (int)so_detail.InvokeMethod(""nSetValue"", ""ItemCode$"", sku);


  • 9.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-16-2018 11:30
    One last (I hope) issue in translating to C#: retval = (int)sage.InvokeMethod(""nGetNextSalesOrderNo"", sOrder); It seems to increment the next order counter in Sage 100, and retval = 1, but the variable does not get populated.


  • 10.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-16-2018 11:54
    before doing the nGetNextSalesOrderNo you are setting it to blank correct, I know if you don't set it to """" then it won't populate properly


  • 11.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-16-2018 11:58
    Yes ,string sOrder = """"; is a previous line.


  • 12.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-16-2018 13:52
    Something like this, methinks: Also what you called ""sage"", I called ""oSO"" but it's whatever is on left of the equal sign of the ""new DispatchObject"" line. Also might want to do this in a Try / Catch: string errorMsg = string.Empty; object[] parms = null; int retVal = 0; string sOrder = string.Empty; parms = new object[] { ""NextSalesOrder$"" }; retVal = (int)oSO.InvokeMethodByRef(""nGetNextSalesOrderNo"", parms); If (retVal == 1) { **sOrder = parms[0].ToString();** } Else { errorMsg = ""Error getting Next Order Number""; throw new Exception(errorMsg); }


  • 13.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 02-18-2018 09:52
    Thank you @AlnoorCassim !


  • 14.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 06-20-2018 09:34
    In C# BOI using the DispatchObject, how does one get the last error info? .sLastErrorMsg does not work


  • 15.  RE: BOI in C# nLogon line from Sage's samples seems to

    Posted 07-17-2018 22:29
    Sorry missed this one. So maybe like this: errorMsg = (string)oSO.GetProperty(""sLastErrorMsg""); throw new ApplicationException(errorMsg);