Scripting

  • 1.  Hi Scripters,I am working with a script to fill

    Posted 05-10-2016 11:50
    Hi Scripters, I am working with a script to fill in the a/r ship to address for new customers. Basically we have some default addresses that we'd like to add based on the customer division. I have it working ~except~ in testing it is overwriting existing ship-to addresses. Bleh. ' ------------------------- START script code -------------------------------------------------------------- 'Title:AR Shipto Default Address Script '***** 'Desc: Add Shipto 0000 and appropriate address based on division of customer '***** 'Bus Object: AR Customer Master table '***** 'Event: Table - Post-write '***** 'Revision History 'Written by Marc C of Technology Integrators 2016 '**** ' ------------------------- START -------------------------------------------------------------- retVal = oScript.DebugPrint(""**Start Script AR Shipto Script.txt***"") oSO_ShipToAddressBUS = 0 oSO_ShippingRateSVC = 0 retVal = 0 tmpARDivisionNo = """" tmpCustomerNo = """" tmpShipToCode = """" tmpSalesDiv1 = """" tmpSalesPer1 = """" udfShipCode = """" SET oSO_ShipToAddressBUS = oSession.AsObject(oSession.GetObject(""SO_ShipToAddress_bus"")) 'SET oSO_ShippingRateSVC = oSession.AsObject(oSession.GetObject(""SO_ShippingRate_svc"")) 'Get the values of the current customer the user is on . . . . retVal = oBusObj.GetValue(""ARDivisionNo$"", tmpARDivisionNo) retVal = oBusObj.GetValue(""CustomerNo$"", tmpCustomerNo) retVal = oScript.DebugPrint(""Customer Division is "" & tmpARDivisionNo & ""CustomerNO is "" & tmpCustomerNo) 'this line /area is incorrect??? retVal = oSO_ShipToAddressBUS.getValue(""ShipToCode$"", tmpShipToCode) 'see if there is a shipto code retVal = oScript.DebugPrint(""Shipto is"" & tmpShipToCode) '****always returns blank!************* if tmpShipToCode = """" then 'setup a new shiptocode this always fires since the code is always blank . . . retVal = oSO_ShipToAddressBUS.SetKeyValue(""ARDivisionNo$"", tmpARDivisionNo) retVal = oSO_ShipToAddressBUS.SetKeyValue(""CustomerNo$"", tmpCustomerNo) retVal = oSO_ShipToAddressBUS.SetKeyValue(""ShipToCode$"", ""0000"") retVal = oSO_ShipToAddressBUS.SetKey() if retVal <>1 then retval=oscript.debugprint(""obusobj set key error was"" & oBusObj.LastErrorMsg) retval=oscript.debugprint(""oso_shipto set key error was"" & oSO_ShipToAddressBUS.LastErrorMsg) end if retVal = oScript.DebugPrint(""Script got to point just after setvalues"") 'set the salesperson as the same as the main customer (could be divisional driven if moved to div. subs) retval = oSO_ShipToAddressBUS.SetValue(""SalespersonDivisionNo$"",tmpSalesDiv1) retval = oSO_ShipToAddressBUS.SetValue(""SalespersonNo$"",tmpSalesPer1) if tmpARDivisionNo = ""00"" then retval = oSO_ShipToAddressBUS.SetValue(""ShipToName$"",""StC"") retval = oSO_ShipToAddressBUS.SetValue(""ShipToAddress1$"",""2150 Main St W"") retval = oSO_ShipToAddressBUS.SetValue(""ShipToAddress2$"","""") retval = oSO_ShipToAddressBUS.SetValue(""ShipToAddress3$"","""") retval = oSO_ShipToAddressBUS.SetValue(""ShipToCity$"",""Marshall"") retval = oSO_ShipToAddressBUS.SetValue(""ShipToState$"",""MN"") retval = oSO_ShipToAddressBUS.SetValue(""ShipToZipCode$"",""56258"") end if retval=oSO_ShipToAddressBUS.write retVal = oScript.DebugPrint(""RetVal after write is now"" & retVal) end if ' ------------------------- end script code -------------------------------------------------------------- I am not properly querying the shiptoaddressbus apparently - the shipto debug line always shows up blank. (the retVal = oScript.DebugPrint(""Shipto is"" & tmpShipToCode) line near the beginning of code) The script does insert the 0000 ship to everytime - and overwrites existing 0000 addresses unfortunately. Hmm so its partly there. I imagine I need to see if the 0000 shipto code exists (direct query or looping??)then insert in the 0000 if it does not exist. Any advice is appreciated. Thank you, Marc


  • 2.  RE: Hi Scripters,I am working with a script to fill

    Posted 05-10-2016 12:10
    You need to set a reference to the record (key) in oSO_ShipToAddressBUS before you can do a GetValue.


  • 3.  RE: Hi Scripters,I am working with a script to fill

    Posted 05-10-2016 12:52
    Maybe use the UI object to GetValue of the ShipToCode field on the screen?


  • 4.  RE: Hi Scripters,I am working with a script to fill

    Posted 05-10-2016 13:00
    Instead of: 'Set oSO_ShipToAddressBUS = oSession.AsObject(oSession.GetObject(""SO_ShipToAddress_svc"")) Use: Set oSO_ShipToAddressBUS = oBusObj.AsObject(oBusObj.GetChildHandle(""ShipToCode""))


  • 5.  RE: Hi Scripters,I am working with a script to fill

    Posted 05-11-2016 09:05
    Thank you @MichaelNottoli @SteveIwanowski , @DanBurleson and @AlnoorCassim ! With your help I was able to get it working. First I set the reference as suggested by using setkeyvalues for the three fields (Division, Customer & shipto code). Then initiated a SetKey which searched based on those three fields we filled in with values. Next a case statement to use the retval of the setkey statement to determine if it was a new record or existing record. (The Case check on the retval was a nugget from @AlnoorCassim and his reference book from class Basic & intermediate Concepts of Scripting page 25. ) In the case statement, I just add the shipto if it doesn't already exist. Here is the snip from the final code to illustrate the above steps. it works great! Thanks again scripting gurus! '**********************snipet start********************************************** ' setup the key values for the ship to address retVal = oSO_ShipToAddressBUS.SetKeyValue(""ARDivisionNo$"", tmpARDivisionNo) retVal = oSO_ShipToAddressBUS.SetKeyValue(""CustomerNo$"", tmpCustomerNo) retVal = oSO_ShipToAddressBUS.SetKeyValue(""ShipToCode$"", ""0000"") 'then set the key for the object retVal = oSO_ShipToAddressBUS.SetKey() 'now check to see if the 0000 ship to was found. 'if the 0000 code is new new add in appropriate data. if existing do nothing. select case retVal 'retval is the set key return of the 0000 shiptocode Case 2'new record process 'new address process goes in here Case 1 'existing record process 'existing address process goes in here Case 0 'error message will display if appropriate sMsg = ""Script Error: Last Error returned from MAS = "" & vbCRLF retMsg = oSession.AsObject(oSession.UI).MessageBox("""", sMsg) End Select '**********************snipet end**************************************