Scripting

  • 1.  hi all,I am trying to get a script together that

    Posted 10-14-2016 12:46
    hi all, I am trying to get a script together that disallows zero quantity Items on a sales order. I'd like it to check quantity when the user exits the quantity column on each line = versus rolling through all the lines before accepting the order is allowed. I have a script put together that does this IF any quantity is keyed into the order qty field. It works as expected EXCEPT if the user just keys through the quantity ordered column without entering anything. For some reason it doesnt pickup the .00 as a quantity then. I am firing on Column Pre Validate for the SO_SalesOrderDetail ItemCode column: ' -------------------------SCRIPT START ------------------------------------ retval = oScript.DebugPrint(""*************START Quantity Checking Script***********"") sItemCode = """" sItemType = """" sComment = """" QtyOrd = 0 ' quantity ordered retval = 0 retval = oBusObj.GetValue(""ItemCode$"", sItemCode)'get the item number the user just entered retval = oBusObj.GetValue(""ItemType$"", sItemType)'get the item type of the item number entered retval = oBusObj.GetValue(""QuantityOrdered"",QtyOrd) 'Get the qty ordered retval = oScript.DebugPrint(""Qty Ordered is "" & QtyOrd & ""*"") ' I get no return here if the user just keys through the quantity column without entering anything. if QtyOrd =0 then if sItemType = ""1"" then 'if this is an item code line then check for non-zero quantity 'in this case we are looking for 0 values - if so then popup a message to the user to alert them as such. sMsg = ""Item "" & sItemCode & "" must have a quantity entered!"" retVal = oScript.SetError(sMsg) 'for script debugging Retval= oSession.AsObject(oSession.UI).MessageBox("""",sMsg) 'display an OK box to the user end if end if retval = oScript.DebugPrint(sItemCode) retval = oBusObj.SetValue(""CommentText$"", "" quantity is"" & qtyord & ""*"") 'put value in comment field for testing retval = oScript.DebugPrint(""*********END Comment Checking Script***************"") ' -------------------------SCRIPT END ------------------------------------ Any help is appreciated! Thank you, Marc


  • 2.  RE: hi all,I am trying to get a script together that

    Posted 10-14-2016 12:47
    Check with @DanBurleson - He is VERY good at this sort of thing. Sometimes too good!


  • 3.  RE: hi all,I am trying to get a script together that

    Posted 10-14-2016 12:52
    Column trigger won't work. Use a line PreWrite, and if ItemType = 1 and quantity ordered = 0 then do a SetError...


  • 4.  RE: hi all,I am trying to get a script together that

    Posted 10-14-2016 13:12
    Kevin Moyes' idea is good. Typically if there is no change in a column value, there is no validation, so the pre-validation will not occur. This can be overridden in the screen library, but not with scripting. Doing it on the line pre-write should be satisfactory for most purposes, though.


  • 5.  RE: hi all,I am trying to get a script together that

    Posted 10-14-2016 13:51
    Thanks guys - that did it! Whew! I appreciate the help! Curious if you can SetFocus like in VB to put the cursor on the quantity column? I looked though my Scripting class materials and didnt find it - i found sendkeys thought maybe that might work but perhaps there is a more elegant way.


  • 6.  RE: hi all,I am trying to get a script together that

    Posted 10-14-2016 15:31
    Marc - It's not discussed in the material too much b/c it's more of a ""post-intermediate"" class concept to discuss ProvideX commands that can be executed with script. One of the later scripts does this after getting the control ID of the field: oScript.Execute(""MULTI_LINE GOTO tmpDestCtl"") However that doesn't apply to grids. It would be something like this but I have NOT tested this. I would put this logic before the SetError() since anything after that may not execute: If QtyOrd =0 and sItemType = ""1"" Then Set oUIObj = oSession.AsObject(oScript.UIObj) oUIObj.GetControlProperty ""GD_LINES"", ""Row"", RowNo oUIObj.GetControlProperty ""GD_LINES"", ""Column$"", ""QuantityOrdered"" oUIObj.GetControlProperty ""GD_LINES"", ""Column"", ColNo oScript.Execute(""tmpRow = "" & RowNo) oScript.Execute(""tmpColumn = "" & ColNo) oScript.Execute(""GRID GOTO GD_Lines.ctl, tmpColumn, tmpRow"") 'SetError Better thought is highlight the cell in the grid instead of setting focus. This I haven't tested either but should work. But if you do this, you may also need a post-write script that sets the Backcolour (use the Queen's English) back to DEFAULT a.k.a. LIGHT GRAY if QtyOrd<>0 and possibly refresh the grid too. If QtyOrd =0 and sItemType = ""1"" Then Set oUIObj = oSession.AsObject(oScript.UIObj) oUIObj.GetControlProperty ""GD_LINES"", ""Row"", RowNo oUIObj.SetControlProperty ""GD_LINES"", ""Row"", CStr(RowNo) oUIObj.SetControlProperty ""GD_LINES"", ""Column$"", ""QuantityOrdered"" oUIObj.SetControlProperty ""GD_LINES"", ""Backcolour"", ""LIGHT YELLOW"" 'SetError