Scripting

  • 1.  I have often wondered something but have not deter

    Posted 01-22-2018 14:19
    I have often wondered something but have not determine how to make it happen in scripting. When I'm on a sales order in the details object I can see the line I'm on, but if I want to see the other lines of that sales order I can't create a new oLines object and movefirst and then loop thru it. What I'm after is a situation where I want to see if the same itemcode is on the current sales order while a user is entering the new item onto the sales order, if so I want to know the quantity of the other line and a warning about the duplicate line and qty. Maybe I'm unaware of something that will allow this but I'm not seeing anything as an option to loop thru the lines that are in memory at the moment. Any thoughts?


  • 2.  RE: I have often wondered something but have not deter

    Posted 01-22-2018 17:50
    I haven't tried this, but can you instantiate another Lines object (off oHeaderObj, like oLines2) then iterate through the lines?


  • 3.  RE: I have often wondered something but have not deter

    Posted 01-22-2018 18:05
    @KevinMoyes had a great idea that he posted to Sage City last year. ""Add a hidden UDF to the header, and a post write script on detail, to concatenate the item code into the UDF (with an appropriate delimiter). Change your script to look for the item code in the header UDF (with appropriate use of the delimiter)."" Seems much easier than looping through the lines with a separate object.


  • 4.  RE: I have often wondered something but have not deter

    Posted 01-23-2018 06:12
    Maybe something like store the current item code, then cycle through looking for that same item code which would let you do anything else. at that point you could either add/delete the line and pass it back to the quantity of the current line or something. issue might be though are comments or other customization fields on each line. though I'm thinking it would be better to simply store the values of both instances delete them and create a totally new line, this would force there to at max only be 2 of any given item. though you'd want to put logic to ignore /c items at least.


  • 5.  RE: I have often wondered something but have not deter

    Posted 01-23-2018 11:00
    Chris I've also done what @KevinMoyes did as well except it was a UDT. I emulated a 3-part key field for UDT which was: SalesOrderNo + | + ItemCode + | + Quantity You could use a symbol other than | (pipe) for your delimiter obviously. Then one script to update the UDT on Detail Post-Write, another to do a Find on the UDT on Post-Validate of Qty Ordered (Pre-Validate if you want to prevent not just warn). Be sure to only include ItemType's you want to check for. A 3rd script to delete the order rows from the UDT. Hmm I think I like Kevin's way of parsing a Header UDF better. Anyway, with my M/D hat on, a typical way is to store the Item + Qty info in a memory channel/file (separate from the memory channel Sage already uses to hold the Lines info). However, I've never tried that with scripting (that is instantiate a 2nd copy of Lines object via Set oLines2 .. GetObject) and not sure what underlying issues there would be to deal with. It would be kind of experimental and ergo recommend you stick with a scripting friendly way that uses either a temp field to store/check data as you go along (like Kevin) or temp table (like me).


  • 6.  RE: I have often wondered something but have not deter

    Posted 01-23-2018 16:45
    Thanks everyone. I will tell you it doesn't work to create a second oLines object, this does cause issues and as you do the .MoveNext() it will move the pointer in both objects. I've been considering the UDT idea using the sales order + linekey + itemcode as the key but I'm just concerned about maintaining that UDT and keeping it in sync, it may be the way I go. The UDF on header is an interesting idea as well, I have used something similar to make it so someone could go into sales order lookup and search what sales orders had an item code on it. I do feel better now knowing there isn't some ""magic"" I wasn't aware of. Thanksk for the feedback!


  • 7.  RE: I have often wondered something but have not deter

    Posted 01-25-2018 15:22
    If you don't mind a mix of vbscript and provideX, you could try out the routines in the two attached files. Have them both in CM\Script. The vbs file needs to be assigned to a business object's event, such as the SO_SalesOrderDetail Pre-Validate event on the QuantityOrdered column. It then calls the providex in the pvc file using the entry label ""loop_through_detail"". The pvc file simply ""returns"" to the vbs file using the ""return"" statement. If you actually want to handle things differently, you could substitute the ""return"" with ""exit x"" where x is is a number which if anything other than -1 will trigger an ""Execute Error x"" in the vbs file. You just have to have an ""On Error Resume Next"" immediately before the line and you can always put ""On Error GoTo 0"" after the line. If you need to get values in between the two scripts, you can either use the SetVar methods of the oScript object or use global provideX variable names which are prefixed with ""%"". For example, in the vbs file, you could set a global variable like this. oScript.Execute(""%myGlobalVariable$=""""Test"""") In the pvc, you would just refer to the variable by name. coSession'UI'MessageBox$("""", %myGlobalVariable$) OR %myGlobalVariable$=""Test"" To get the value of a provideX variable in the vbs script, you use the following. sGlobalVariable = """" sGlobalVariable = oScript.Evaluate(""%myGlobalVariable$"") You just have to remember when dealing with provideX that anything string related needs to have the ""$"" at the end. You cannot, for example, use the following. %myGlobalVariable$=5 Also %myGlobalVariable$ and %myGlobalVariable are two different variables as far as provideX is concerned. If you are really curious, i also attached the ProvideX documentation which you might find useful if you pursue this.

    Attachment(s)

    pdf
    ProvideX_Version_7.pdf   7.39 MB 1 version
    pvc
    Loop_Through_Detail.pvc   1001 B 1 version
    zip
    Loop_Through_Detail.zip   269 B 1 version


  • 8.  RE: I have often wondered something but have not deter

    Posted 01-30-2018 19:25
    David I just wanted to say thank you for this very outside the box solution, I will keep this in mind, more complex than one would want it to be but a solution none the less!