Scripting

Expand all | Collapse all

Any scripting gurus out there who happen to know h

Dan Burleson

Dan Burleson07-21-2017 08:11

  • 1.  Any scripting gurus out there who happen to know h

    Posted 07-20-2017 17:56
      |   view attached
    Any scripting gurus out there who happen to know how i can write to a UDF in SO_SalesOrderHistoryHeader using BOI. I've seen examples of writing to AR_InvoiceHistoryHeader but can't find one for SO_SalesOrderHistoryHeader. I'm using the following code from the button ""Link 1"" on a dialogue panel attached to Sales Order and Quote History Inquiry (I have also tried from a button script on Sales Order Entry and same results) ____________________________ nRetval = 0 sRetval = """" nRetval = oScript.SetUIControl(""UDF_PROJECT"", ""UNLOCK"") nRetval = oScript.SetUIControl(""UDF_PROJECT"", ""ENABLE"") sNewProject = """" nRetval = oBusObj.GetValue(""UDF_PROJECT$"", sNewProject) nRetval = oSession.SetProgram(oSession.LookupTask(""SO_SALESORDER_UI"")) oSession.LastErrorMsg = """" nSOHistoryBus = 0 nSOHistoryBus = oSession.NewObject(""SO_SalesOrderHistoryInquiry_Bus"") 'sRetval = oSession.AsObject(oSession.UI).MessageBox("""", ""nSOHistoryBus: "" & nSOHistoryBus & vbCrLf & ""Last Error Msg: "" & oSession.LastErrorMsg) nRetval = oScript.DebugPrint(""nSOHistoryBus: "" & nSOHistoryBus & "" | "" & ""Last Error Msg: "" & oSession.LastErrorMsg) If nSOHistoryBus > 0 Then Set oSOHistoryBus = oSession.AsObject(nSOHistoryBus) sKey = """" sKey = oBusObj.GetKeyPadded() oSOHistoryBus.LastErrorMsg = """" nRetval = oSOHistoryBus.SetKey(sKey) 'sRetval = oSession.AsObject(oSession.UI).MessageBox("""", ""Key: "" & sKey & vbCrLf & ""nRetval: "" & nRetval & vbCrLf & ""Last Error Msg: "" & oSOHistoryBus.LastErrorMsg) nRetval = oScript.DebugPrint(""Key: "" & sKey & "" | "" & ""nRetval: "" & nRetval & "" | "" & ""Last Error Msg: "" & oSOHistoryBus.LastErrorMsg) If nRetval = 1 Then oSOHistoryBus.LastErrorMsg = """" nRetval = oSOHistoryBus.SetValue(""UDF_PROJECT$"", sNewProject) 'sRetval = oSession.AsObject(oSession.UI).MessageBox("""", ""nRetval: "" & nRetval & vbCrLf & ""Last Error Msg: "" & oSOHistoryBus.LastErrorMsg) nRetval = oScript.DebugPrint(""nRetval: "" & nRetval & "" | "" & ""Last Error Msg: "" & oSOHistoryBus.LastErrorMsg) oSOHistoryBus.LastErrorMsg = """" nRetval = oSOHistoryBus.Write() 'sRetval = oSession.AsObject(oSession.UI).MessageBox("""", ""nRetval: "" & nRetval & vbCrLf & ""Last Error Msg: "" & oSOHistoryBus.LastErrorMsg) nRetval = oScript.DebugPrint(""nRetval: "" & nRetval & "" | "" & ""Last Error Msg: "" & oSOHistoryBus.LastErrorMsg) End If End If ____________________________________________ Any ideas? Will this only work from an external BOI script?


  • 2.  RE: Any scripting gurus out there who happen to know h

    Posted 07-20-2017 20:10
    Since it's a security error, I'm guessing a SetValueNoValidation won't work either. You'll probably need to hack the data dictionary.


  • 3.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 00:35
    Yes, I tested this with the same _UI and _Bus in a BOI and nSetValue works.


  • 4.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 05:07
    Man, how can the same objects behave differently?!?


  • 5.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 06:09
    The business object you instantiate is one of 'Inquiry' ... I thought those inherently could not write.... Am I wrong?


  • 6.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 06:38
      |   view attached
    According to some posts, the ""bus"" objects were originally created for history objects so you could update them using VI. I have attached a script posted by Alnoor that shows how to update a UDF in AR_InvoiceHistoryHeader by setting the program to AR_Customer_UI. In my above script, the SetValue works fine, it is the write that is failing. I have even tried setting the program to VI_Import_UI hoping that would trick the security, no dice. I'm going to try this as an external script and see what happens.

    Attachment(s)



  • 7.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 07:13
    UPDATE: this little snippet works as an external BOI script. really would have liked for this to work from a button script though but i can work with this. oSS.nSetProgram(oSS.nLookupTask(""SO_SalesOrder_UI"")) Set oSOSalesOrderHistory = oPVXSession.NewObject(""SO_SalesOrderHistoryInquiry_Bus"", oSS) nRetval = oSOSalesOrderHistory.nSetKey(""0000139"") sRetval = oUI.sMessageBox("""", ""Set Header Key: "" & nRetval & vbcrlf & oSOSalesOrderHistory.sLastErrorMsg) retval = oSOSalesOrderHistory.nSetValue(""UDF_Project$"", ""Test"") retval = oSOSalesOrderHistory.nWrite() retval = oUI.sMessageBox("""", ""Header Write: "" & retval & vbcrlf & oSOSalesOrderHistory.sLastErrorMsg) retval = oSOSalesOrderHistory.nClear() oSOSalesOrderHistory.DropObject()


  • 8.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 07:41
    UPDATE 2: i was curious what the security values were when i was running this from a button script and turns out SecurityAccess property is 7 and TaskType is ""M"" so i see no reason why the write shouldn't succeed.


  • 9.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 08:11
    I often don't use nWrite without an issue.


  • 10.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 09:25
    @DanBurleson , are you saying you have been able to successfully write to a history table using an ""internal"" script or only ""external"" as indicated by ""nWrite""?


  • 11.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 10:32
    External BOI script using nSetValue w/o nWrite.


  • 12.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 10:34
    would the header values that were changed even be saved if you don't use nWrite? i wouldn't think they would.


  • 13.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 10:39
    Yes, but only in an alternate universe. There was indeed a nWrite behind the nSetValue. Sorry for any confusion.


  • 14.  RE: Any scripting gurus out there who happen to know h

    Posted 07-21-2017 10:43
    Too bad that doesn't work from a button script...


  • 15.  RE: Any scripting gurus out there who happen to know h

    Posted 07-22-2017 16:52
    Hey David - It's all about the SecurityAccess property and when the SetProgram / LookupTask can actually be executed. You get the rights error because oSOHistoryBus.SecurityAccess = 0 and that is true in all Inquiry screens (which trumps everything else) and even with a S/O Entry button like you had tried. It works in BOI because you can set the security context using SetProgram / LookupTask then NewObject, but when you run a task inside the Launcher, the GetObject (which will run NewObject) will end up choosing SO_SalesOrderHistoryInquiry_UI as the program (instead of what you wanted to choose with SetProgram) and by its rules sets SecurityAccess = 0. So you don't get to change it, try as you may. As you know with V/I, or SYZCON or some kind of ProvideX, it works. Main reason is you are using the pvx NEW function instead of GetObject / NewObject method. So if running S/O Entry button script (or Cust Maint) or anywhere oBusObj.SecurityAccess > 0 (the _initial_ SecurityAccess) you can make it work like this: **Script change:** retVal = oScript.Execute(""PERFORM "" + CHR(34) + ""..\CM\Script\NewUpSOHistoryBus.pl"" + CHR(34)) Set oSOHistoryBus = oSession.AsObject(oScript.Evaluate(""oSOHistoryBus"")) **Add Perform Logic: NewUpSOHistoryBus.pl** ---------------------------------- IF NOT(oSOHistoryBus) { oSOHistoryBus = NEW(""SO_SalesOrderHistoryInquiry_Bus"", %SYS_SS) ! This version should set SecurityAccess = 7 if checked in Role Maint } EXIT But if running button script directly from S/O Order History Inquiry then _initial_ SecurityAccess = 0 to begin with so it can't be done with scripting. Needs to be Perform Logic button all the way or needs a ProvideX class override or some other neat trick.


  • 16.  RE: Any scripting gurus out there who happen to know h

    Posted 07-22-2017 16:59
    That makes sense. I didn't know that NewObject works the same as GetObject in an internal script. Good to know. I ended up writing it as an external but I think I'll change it as I would prefer it to use the current session.


  • 17.  RE: Any scripting gurus out there who happen to know h

    Posted 07-24-2017 09:47
    I've attached what I ended up using thanks to Alnoor's insight. SO_UnlockHistoryFields is a button script that simply unlocks the desired fields but only if the order status equals ""C"". SO_UpdateSalesOrderHistory is a button script that then handles getting and updating the record. SO_AdditionalOnExit is a UI OnExit event script attached to the dialogue panel where these UDFs are located. It just makes sure that any ""unsaved"" changes are ""cleared"" so the user doesn't get the useless ""do you want to save changes"" prompt when they step off the record since we're in an inquiry task, they can't save it even if they click yes. It also locks and disables the fields again.

    Attachment(s)