Sage 100

 View Only
Expand all | Collapse all

Help with scripting Qty Used to Qty Required for each JT Parts Usage line

  • 1.  Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 04-28-2020 18:54
    Hi - I've never done a button script before to read a Lines tab value and write to a Lines tab value, so I know I'm doing something wrong but can't determine what, and I'm wondering if there is also something special to consider for JobOps tables? I am trying to work in Work Ticket Entry > Parts Entry tab to allow users to click a button that reads the "Qty Required" value and populates the "Qty Used" field with the same value, and do that for all line items that I will specify later. From what I can tell, the fields I should be mapping in are from SO_SalesOrderDetail Quantity Ordered and Quantity Shipped. The script recognizes the values I'm reading, but it will not set or write. Am I missing something simple or should I stop here and give this to my Development team instead?

    sItemCode = "" : sItemType = "" : nQtyReqd = 0

    Set oLines = oBusObj.AsObject(oBusObj.Lines)

    retVal = oLines.MoveFirst()

    Do Until cBool(oLines.EOF)

     retVal = oLines.GetValue("ItemType$", sItemType)

    msgbox(sItemType)

     If sItemType = "1" Then
      retVal = oLines.GetValue("ItemCode$", sItemCode)
      retVal = oLines.GetValue("QuantityOrdered", nQtyReqd)
    msgbox(nQtyReqd)
    End If

    retVal = oLines.MoveNext()

    Loop

    retVal = oLines.SetValue("QuantityShipped", nQtyReqd)

    Any help would be greatly appreciated. Thanks in advance! #scripting


    ------------------------------
    Amber Prayfrock, Blytheco
    ------------------------------


  • 2.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 04-28-2020 21:35
    Edited by David Speck II 04-28-2020 21:55
    Sounds like you have this button script on the lines tab as well and you are trying to set the value for the currently selected line when the button is clicked, correct?
    If yes, then your changes with the SetValue isn't having any effect because using MoveNext takes you off the line you were on when the button was clicked so it is no longer the current record being edited.
    At the beginning of your script, before you move to any other lines, you need to get the current key and save it into a variable that you will later use in either a SetKey or EditLine.
    Also, since this is a button script, you may want to instead use the following code instead of SetValue.
    oUIObj.InvokeChange "QuantityShipped", nQtyReqd, "GD_Lines"


    So something like this should do the trick, assuming JobOps doesn't interfere. Avoid using the VBScript MsgBox in button scripts where business objects are used. This will cause your  script to hang if used on an Advanced install so i have substituted them with the MessageBox method.

    sItemCode = "" : sItemType = "" : nQtyReqd = 0
    
    Set oLines = oBusObj.AsObject(oBusObj.Lines)
    
    sCurrentKey = "" : sCurrentKey = oLines.GetKey()
    
    retVal = oLines.MoveFirst()
    
    Do Until cBool(oLines.EOF)
    
     retVal = oLines.GetValue("ItemType$", sItemType)
    
    oSession.AsObject(oSession.UI).MessageBox "", "sItemType: " & sItemType
    
     If sItemType = "1" Then
      retVal = oLines.GetValue("ItemCode$", sItemCode)
      retVal = oLines.GetValue("QuantityOrdered", nQtyReqd)
    oSession.AsObject(oSession.UI).MessageBox "", "nQtyReqd: " & nQtyReqd
    End If
    
    retVal = oLines.MoveNext()
    
    Loop
    
    oLines.EditLine sCurrentKey ' This puts the original line back into an edit state.
    
    oUIObj.InvokeChange "QuantityShipped", nQtyReqd, "GD_Lines"
    
    oLines.Write ' Normally, traversing lines through the Grid's intereface will trigger a line to "Write" however since this is being done from a button script, it is best to make sure to call the Write method to be sure your changes are saved.
    
    oLines.EditLine sCurrentKey ' Write tends to clear the current record so this puts the original line back into an edit state so if the user makes another change on the current line, it won't cause any errors.


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 3.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 04-29-2020 08:45
    Interesting Ask.  I'm curious if you will get this to work with David's Help; as it is often requested by JobOps Clients.  It could be easier than "Parts Usage"; I think.  Report back if you get it to work, to satisfy my curiosity.  :)​

    ------------------------------
    Madeline Stefanou
    RKL eSolutions, LLC
    ------------------------------



  • 4.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 04-30-2020 14:32
    @David Speck II, thank you very much for ​​the quick response on Tuesday. I ended up with another big project yesterday so couldn't come back to this. I understand the "InvokeObject" now to write the value per line, so that is extremely helpful.  But I can't seem to understand why it will not write to every one of my lines without me clicking on each line. This is what I'm seeing happen at the moment: When I first move to the Parts Usage tab, I get an "Item Code is Required" so the script is trying to write to the next blank row. If I then highlight any item row and click my button script, the Qty Shipped value from the last line on the order will write to the active line. So the script is looping and seeing all items and quantities, but it's not writing to each line before moving to the next. I attempted to mess with the order of the move and loop functions but that doesn't work either (not that I expected it to but didn't figure there was any harm in trying). This is what I currently have - please let me know if you recognize the issue:

    sItemCode = "" : nQtyReqd = 0 : nQtyReqdInc = 0 : nQtyReqdRound = 0

    Set oLines = oBusObj.AsObject(oBusObj.Lines)

    sCurrentKey = "" : sCurrentKey = oLines.GetKey()

    retVal = oLines.MoveFirst()

    Do Until cBool(oLines.EOF)

    retVal = oLines.GetValue("ItemCode$", sItemCode)

    If Left(sItemCode,2) = "P-" Then
    retVal = oLines.GetValue("QuantityOrdered", nQtyReqd)
    nQtyReqdInc = nQtyReqd + .5
    nQtyReqdRound = ROUND(nQtyReqdInc,0)
    End If

    retVal = oLines.MoveNext()

    Loop
     
    retVal = oLines.EditLine(sCurrentKey)

    retVal = oUIObj.InvokeChange("QuantityShipped", nQtyReqdRound, "GD_Lines")

    retVal = oLines.Write()

    retVal = oLines.EditLine(sCurrentKey)

    ------------------------------
    Amber Prayfrock, Blytheco
    ------------------------------



  • 5.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 04-30-2020 14:53
    Based on your OP, i had thought you were only trying to update the currently selected line so the script sample i included was with that in mind, you would first select the line you wanted to updated and then click the button.

    If you are trying to loop through and update every line (that fits your criteria), then you need to move the InvokeChange and Write to inside of the loop and you can probably get rid of the first EditLine that was before the InvokeChange since the last EditLine is only need to make sure to pair the Lines object's key up with the grid's row that was selected when the button was clicked.

    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 6.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 04-30-2020 23:10
    Thank you so much, David. Sorry that I was not clear with my need for the population of all lines. Now I understand better the order of events. I've just got to figure out the grid refresh and I should be good. Thank you again for your mentoring!

    ------------------------------
    Amber Prayfrock, Blytheco
    ------------------------------



  • 7.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 04-30-2020 23:34
    Since this is a button script, you should be able to use the following at the end of your script.
    oScript.LoadGrid "GD_Lines"
    oScript.LinesAdded = -1


    Also, since you are updating more than just the selected line when the button is clicked, replace the oUIObj.InvokeChange method with the oLines.SetValue method. Reloading the grid should take care of making sure everything is displayed correctly.



    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 8.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 05-06-2020 15:59
    Thanks again for all of your help, David. I really appreciate the learning.

    Madeline, this was the script that I ended up with that got me almost there. There appears to be something different with JobOps that won't refresh the grid like Sales Order Entry does. I have to move to another tab in Work Ticket Entry and then back to Parts in order to see the Quantity Required populated.

    sItemCode = "" : nQtyReqd = 0 : nQtyReqdInc = 0 : nQtyReqdRound = 0

    Set oLines = oBusObj.AsObject(oBusObj.Lines)

    retVal = oLines.MoveFirst()

    Do Until cBool(oLines.EOF)

    retVal = oLines.GetValue("ItemCode$", sItemCode)

    If Left(sItemCode,2) = "P-" Then

    retVal = oLines.GetValue("QuantityOrdered", nQtyReqd)
    nQtyReqdInc = nQtyReqd + .5
    nQtyReqdRound = ROUND(nQtyReqdInc,0)

    retVal = oLines.SetValue("QuantityShipped", nQtyReqdRound)

    retVal = oLines.Write()

    End If

    retVal = oLines.MoveNext()

    Loop

    oScript.LinesAdded = -1
    retVal = oScript.LoadGrid("GD_Lines")

    retVal = oScript.InvokeButton("fldr.PMAIN")
    'retVal = oScript.InvokeButton("fldr.PPARTS")


    ------------------------------
    Amber Prayfrock, Blytheco
    ------------------------------



  • 9.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 05-06-2020 16:59

    Try the following code to see if it will refresh the grid. If this doesn't work, it could be possible that JobOps named their grid control something else and i don't have an opportunity to find out exactly what it is at the moment.

    nGD_Lines_Ctl = 0 : oUIObj.GetControlProperty "GD_Lines", "Ctl", nGD_Lines_Ctl : nGD_Lines_Ctl = CLng(nGD_Lines_Ctl)
    If nGD_Lines_Ctl > 0 Then 
    	oUIObj.InitDefaultRowState
    	oUIObj.ClearTotals
    	oUIObj.ClearGrid nGD_Lines_Ctl
    	oUIObj.LoadLines nGD_Lines_Ctl
    	oUIObj.SetStartingRow nGD_Lines_Ctl
    End If​


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 10.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 05-06-2020 20:12
    Well, that worked perfectly! You are amazing!

    I will be studying this "GetControlProperty" and "SetControlProperty" more to try to understand what you did, but that is extremely helpful! Thank you so much!

    ------------------------------
    Amber Prayfrock, Blytheco
    ------------------------------



  • 11.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 05-06-2020 20:26
    Edited by David Speck II 05-06-2020 20:27
    Refer to the scripting.docx for more info on those methods.

    In short, they allow you to get or set control objects' properties. In my example, the value we need in order to pass to the subsequent methods in the "Ctl" value, this is a unique control object identifier, every control has one, from buttons, to multi-lines, to grids.

    Refer to the ProvideX manual for properties that are available on a per control object basis.
    https://manual.pvxplus.com/PXPLUS/control_object_properties/graphical_control_objects.htm

    For the entire manual, go to this link and navigate the tree.
    https://manual.pvxplus.com/

    This section deals with the control objects and properties.


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 12.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 05-07-2020 08:13
    Thank you!! I have those URLs saved now.

    ------------------------------
    Amber Prayfrock, Blytheco
    ------------------------------



  • 13.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 06-22-2020 10:17
    Amber,

    Just curious .... would the Time Tracker Auto Issue parts function not have worked for this client?

    ------------------------------
    Jane Scanlan
    Partner, Next Level Manufacturing Consulting Group
    Next Level Manufacturing Consulting Group
    Chanhassen MN
    952-210-7758
    ------------------------------



  • 14.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 06-22-2020 13:24
    Hmmm, not sure. I will have to remember to look at that next time I'm on their system since I don't have my own JobOps. We had to issue only for certain item numbers so not sure if "Time Tracker Auto Issue" would allow us conditions?

    ------------------------------
    Amber Prayfrock, Blytheco
    ------------------------------



  • 15.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 11-25-2020 15:47
    Edited by Dan Burleson 11-25-2020 16:11
    @David Speck II Do you see any reason why this snippet wouldn't work for a button script​? (also tried AddLines and LoadGrid):
    oScript.LoadGrid "GD_Lines"
    oScript.LinesAdded = +1  ​

    I get an error 438 w/"Object doesn't support this property or method: 'oSOUIObj.ClearTotals'". Without this ClearTotals statement it doesn't update the totals. I've tried this (as well as instantiating another oUIObj) in a button script Cash Receipts Entry (grid is "GD_Lines") and the totals don't update after having entered a new row.

    ------------------------------
    Dan Burleson
    Software Consultant
    Connex Software
    Corvallis OR
    541-224-6642
    ------------------------------



  • 16.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 11-25-2020 15:53
    Are you using 
    oScript.LoadGrid "GD_Lines"
    oScript.LinesAdded = -1​

    or 
    nGD_Lines_Ctl = 0 : oUIObj.GetControlProperty "GD_Lines", "Ctl", nGD_Lines_Ctl : nGD_Lines_Ctl = CLng(nGD_Lines_Ctl)
    If nGD_Lines_Ctl > 0 Then 
    	oUIObj.InitDefaultRowState
    	oUIObj.ClearTotals
    	oUIObj.ClearGrid nGD_Lines_Ctl
    	oUIObj.LoadLines nGD_Lines_Ctl
    	oUIObj.SetStartingRow nGD_Lines_Ctl
    End If​​


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 17.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 11-25-2020 16:14
    Edited by Dan Burleson 11-25-2020 16:14
    I tried both. One difference is that I am adding deleting a line and adding a line in the same button script and doing the LinesAdded twice - once negative and again positive 1. (my prior post was updated after you asked.)

    ------------------------------
    Dan Burleson
    Software Consultant
    Connex Software
    Corvallis OR
    541-224-6642
    ------------------------------



  • 18.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 11-25-2020 16:18
    Try using just the following after you are done adding/deleting lines. Remove everything else that has to do with refreshing the grid.
    oUIObj.PostLoadPLines​


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 19.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 11-25-2020 16:30
    Voila! That worked. I fully expect you see you walking on water soon (or maybe I just did). I will be going back to the Px Plus Reference manual.

    ------------------------------
    Dan Burleson
    Software Consultant
    Connex Software
    Corvallis OR
    541-224-6642
    ------------------------------



  • 20.  RE: Help with scripting Qty Used to Qty Required for each JT Parts Usage line

    Posted 11-25-2020 16:36
    Edited by David Speck II 11-25-2020 16:36
    I don't think the reference manual would have helped you with this one. The case receipts ui object doesn't even have a ClearTotals method like the other lines object i'm used to. Regardless, the methods that i have posted in this thread are all sage 100 specific methods, however, some of them do require property values of the control objects. These various properties and their potential values can be found in the reference manual.

    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------