Sage 100

 View Only
Expand all | Collapse all

Not sure of the best place to post this but here i

  • 1.  Not sure of the best place to post this but here i

    Posted 03-23-2018 13:52
    Not sure of the best place to post this but here it goes: I am writing a script that is intended to add up particular lines on a sales order and create a new line with a miscellaneous item using the total qty shipped for those items. The script works great when it is run as a Pre-Totals on the Sales Order Header. The problem is, this client also has JobOps and I believe the JobOps functionality is interfering with the script. When the user goes from the Work Ticket back to Sales Order, it seems to unexpectedly delete a miscellaneous item from the order/work ticket. When I figure out how to get around this with one work ticket step, it deletes a miscellaneous item on the next step. I am using this script as a Pre-Write on the Sales Order Header since the Pre Totals won't work from Work Ticket. Here is the script: JobType = """" ExtAmtM = 0 ExtAmtI = 0 ItemType = """" ItemCode = """" QtyOrd = 0 TotExt1 = 0 TotExt2 = 0 TotExt = 0 Override = """" MiscType = """" ItemType = """" sCurKey = """" retVal = oBusObj.GetValue(""JT158_WTClass$"",JobType) if JobType <> ""SER"" then Exit Sub End if Set oLines = oBusObj.AsObject(oBusObj.Lines) retVal = oLines.MoveFirst() Do Until CBool(oLines.EOF) = True retVal = oLines.GetValue(""ItemCode$"", ItemCode) retVal = oLines.GetValue(""UDF_OVERRIDE$"",Override) If ItemCode = ""/SUPPLCHG"" and Override = ""N"" then retVal = oLines.Delete() End If retVal = oLines.MoveNext() Loop retVal = oLines.MoveFirst() Do Until CBool(oLines.EOF) = True set oItem = oLines.AsObject(oLines.GetChildHandle(""ItemCode"")) retVal = oItem.GetValue(""ItemType$"",ItemType) if ItemType <> 1 then retVal = oItem.GetValue(""UDF_LABOR_SUPPLY$"",MiscType) if MiscType = ""Supply"" then retVal = oLines.GetValue(""ExtensionAmt"", ExtAmtM) TotExt1 = TotExt1 + ExtAmtM End if End if retVal = oLines.MoveNext() Loop retVal = oLines.MoveFirst() Do Until CBool(oLines.EOF) = True retVal = oItem.GetValue(""ItemType$"",ItemType) If ItemType = ""1"" then retVal = oLines.GetValue(""ExtensionAmt"", ExtAmtI) TotExt2 = TotExt2 + ExtAmtI End if retVal = oLines.MoveNext() Loop TotExt = TotExt1 + TotExt2 sCurKey = oLines.GetKey() retVal = oLines.InsertLine(sCurKey, ""A"") retVal = oLines.SetValue(""ItemCode$"",""/SUPPLCHG"") if TotExt <= 900 then retVal = oLines.SetValue(""QuantityOrdered"", TotExt) else retVal = oLines.SetValue(""QuantityOrdered"", 900) end if retVal = oLines.Write()


  • 2.  RE: Not sure of the best place to post this but here i

    Posted 03-23-2018 14:34
    @DanBurleson has written a similar script in invoice entry for me. Has worked tirelessly for many moons now. Perhaps he will see this bat signal shining in the sky.


  • 3.  RE: Not sure of the best place to post this but here i

    Posted 03-23-2018 14:48
    Did you try the troubleshooting suggestion I posted on Sage City? https://sagecity.na.sage.com/support_communities/sage100_erp/f/sage-100-business-object-interface/107463/script-deleting-misc-item-line


  • 4.  RE: Not sure of the best place to post this but here i

    Posted 03-23-2018 14:53
      |   view attached
    @Sage100AdvancedScripting - @SteveMarek you may want to join the Sage 100 Advanced Scripting group. Attached are instructions for joining groups (and following members).

    Attachment(s)

    pdf
    socialcast_following.pdf   84 KB 1 version


  • 5.  RE: Not sure of the best place to post this but here i

    Posted 03-23-2018 14:59
    Hi Kevin, I did try and it is showing me the info that is coming through on each step. What seems to be happening is that when I add a new step it is just removing one of the lines, even if I remove the delete part from the script. So the delete portion has been commented out but there are still lines being removed. I thought this may be related to the way JobOps writes lines, maybe they are writing on top of each other and removing lines based on that? I will also respond in Sage City, just thought I would broaden the audience on this.


  • 6.  RE: Not sure of the best place to post this but here i

    Posted 03-23-2018 15:07
    If the script is removing lines even without the delete function, I'm at a loss for ideas. I was thinking the ""if"" was not evaluating properly. Perhaps the InsertLine isn't working correctly, and it is overwriting a line instead of adding one?


  • 7.  RE: Not sure of the best place to post this but here i

    Posted 03-23-2018 15:20
    Just a guess but think you would need to set some to the JobOps fields. Like JT158_WTPart$ = N , JT158_WTChargePart$ = Y, JT158_WTParent$ = N and JT158_WTPrintPart$ = Y these values get set when add an item to a sales order, even when it's not attached to a work ticket. This would not link the misc item to a specific work ticket, just add it as a line on the sales order.


  • 8.  RE: Not sure of the best place to post this but here i

    Posted 03-23-2018 17:11
    @SteveMarek are you doing InsertLine(Current Key, ""A"") because you need to specifically insert the misc charge After that item? If you don't mind the new misc charge you're adding to be the last line, I suggest using the good old reliable AddLine() with no arguments passed to it. Who knows what actually happens with JobOps and what script events it triggers when W/T Entry is closed and it returns back to Lines.


  • 9.  RE: Not sure of the best place to post this but here i

    Posted 03-26-2018 13:38
    So I have done some more testing and found that the script works fine on an install without JobOps (with the JobOps stuff commented out) and it also works as expected on this install if set to a Pre-Totals event. It seems that the Pre-Write event can't be used on the JobOps SO Entry table, that it bumps up against the JobOps programming during the Write. The client can't use the Pre-Totals event as that requires a change to be made on the Sales Order to calculate. They make all of the changes in the Work Ticket Entry. Has anyone used Post Write event? I tried this but ran into issues with permissions but the user permissions are totally open. The client is running 2 scripts on this table with different priorities and are using Sage Advanced if this info brings any more clarity to the situation. I did try all the suggestions here though and appreciate the help! I had originally used AddLine but in troubleshooting it decided to try InsertLine. I changed it back to AddLine which is better.


  • 10.  RE: Not sure of the best place to post this but here i

    Posted 03-26-2018 14:04
    Just thinking out loud what about a different approach where they click on a button in the Lines tab instead of an Event script? It would pretty much the same script you have but with these exceptions: 1) At the beginning, SetValue to a UDF as a flag (or could be storage variable) to know they've pressed the button. You would also have a Table PreWrite script that check this value if they forgot to press the button. 2) At the end, refresh the grid.


  • 11.  RE: Not sure of the best place to post this but here i

    Posted 03-29-2018 10:39
    I think a button script could get around the issue but the customer would prefer a script that runs automatically so his users don't have to remember to click a button. Have you worked with the Post-Write event before and are there special tricks to it? Or is that just an event that isn't used because it is too problematic? If we did go in the direction of a button script, would there be a lot to change in the script? I haven't done one before but understand tables are called in a different way. Are there any resources you know of for how to write scripts for a button rather than event?


  • 12.  RE: Not sure of the best place to post this but here i

    Posted 03-29-2018 14:44
    Post write won't necessarily trigger totals to be recalculated (order totals / taxes). A button script which doesn't need user input can be identical to a normal script. Just set it to run on the server in the panel settings.