Scripting

  • 1.  Hi all - I have a script that runs on invoice de

    Posted 08-22-2017 18:01
    Hi all - I have a script that runs on invoice detail lines. It is a button script the user can click if the invoice meets certain user-determined criteria. The button script loops through all the detail lines and checks the warehouse code assigned to each line. Once I have the warehouse value for the line, then I want to look at the WarehouseCode table and get a value of a UDF that is assigned on each warehouse code that determines its Cost Code. Next plug that cost code back in to the line, write the line, move to the next line and repeat. Below is the code snippet I have: '***************************************************CODE START Set oLines = oSession.AsObject(oBusObj.Lines) retVal = oLines.movefirst() 'goto top line of details 'now loop through detail lines of order do until cBool(oLines.EOF) 'first get item type, item #, unit price values retval = olines.getvalue(""ItemType$"",sItemType) retval = olines.getvalue(""ItemCode$"",sItemCode) retval = olines.getvalue(""UnitPrice"",nUnitPrice) 'retVal = oScript.DebugPrint(nUnitPrice) retval = olines.getvalue(""CostCode$"",sCostCode) retval = olines.getvalue(""CostType$"",sCostType) retval = olines.getvalue(""WarehouseCode$"",sWhsecode) retVal = oScript.DebugPrint(""Item Detail found "" & sItemCode) retval = oscript.debugprint(""CostCode = "" & sCostCode) retval = oscript.debugprint(""CostType = "" & sCostType) retval = oscript.debugprint(""warehouse is "" & sWhsecode) 'now set the cost type and cost code Set oWhse = oLINES.AsObject(olines.GetChildHandle(""WarehouseCode"")) sWhseCostCodeUDF = """" retVal = oWhse.GetValue(""UDF_WHCOSTCODE$"", sWhseCostCodeUDF) 'get the value of the UDF here - UDF name likely will be different on live data! retval = olines.setvalue(""CostCode$"",sWhseCostCodeUDF) retval = olines.write() 'finally! Write the line back retval = olines.movenext() loop '****************************************CODE END I think I have something wrong with the child handle part of getting the udf. It seems to not be grabbing the line level warehouse code. Originally i had the line reading: Set OWhse = oBusObj.AsObject(olines.getchildhandle(""warehousecode"")) but that didnt work either. Seems like this part is where the problem is: Set oWhse = oLINES.AsObject(olines.GetChildHandle(""WarehouseCode"")) sWhseCostCodeUDF = """" retVal = oWhse.GetValue(""UDF_WHCOSTCODE$"", sWhseCostCodeUDF) 'get the value of the UDF here - UDF name likely will be different on live data! I removed those three lines, and put in a 'manual' assignment to see if i was inserting the data to the cost code field incorrectly, but this works as expected: if sWhsecode = ""VAB"" then retval = olines.setvalue(""CostCode$"",""SVCANDY"") retval = oscript.debugprint(""IN VAB Loop"") end if any ideas? Thank you,Marc


  • 2.  RE: Hi all - I have a script that runs on invoice de

    Posted 08-22-2017 18:05
    i believe the ""AsObject"" method is only available to the ""oSession"" object. I don't think i've ever had any luck using anything other then ""oSession.AsObject"".


  • 3.  RE: Hi all - I have a script that runs on invoice de

    Posted 08-22-2017 18:09
    Thanks David. When i tried osession that doesnt behave properly either. How do i specify i want the line level warehouse instead of the invoice header warehouse? In this particular situation there can be multiple warehouses.


  • 4.  RE: Hi all - I have a script that runs on invoice de

    Posted 08-22-2017 18:17
    Right, i always like to throw the return value of GetChildHandle into a numeric variable first, then test if the variable is greater than 0, if it is, then proceed to call the AsObject. if the variable equals zero, then you failed to get the handle. Also, on a few occasions, i've seen cases where the child object for whatever reason was not on a record like i expected it to be when moving between lines, i was able to solve this by adding ""object.ReadAdditional()"" prior to getting the child handle. Someone else may be able to weigh in on the usefulness or if ReadAdditional should be used in this way. nWarehouseChild = oLines.GetChildHandle(""WarehouseCode"") if nWarehouseChild > 0 then set oWarehouseChild = oSession.AsObject(nWarehouseChild) else retval = oScript.DebugPrint(""Failed to get child object handle to IM_Warehouse_Svc"") end if


  • 5.  RE: Hi all - I have a script that runs on invoice de

    Posted 08-22-2017 18:22
    Also, just to clarify, you are after a value in IM_Warehouse not IM_ItemWarehouse, right? The child handle you get from the line warehouse code is for IM_Warehouse not IM_ItemWarehouse.


  • 6.  RE: Hi all - I have a script that runs on invoice de

    Posted 08-22-2017 18:26
    Thank you for the followup replies David. IM_Warehouse - yes that is where we have the UDF. I'll give the code you shared a whirl.


  • 7.  RE: Hi all - I have a script that runs on invoice de

    Posted 08-22-2017 18:47
    For the record, i stand corrected, AsObject worked fine in v2017 when i tested calling it like ""oBusObj.AsObject"" and even like ""oBusObj.AsObject(oBusObj.Lines).AsObject"" just for fun.