Scripting

Expand all | Collapse all

Why is it always the simple things that seem to be

Steve Iwanowski

Steve Iwanowski11-03-2016 09:12

Kevin Moyes

Kevin Moyes11-03-2016 09:30

  • 1.  Why is it always the simple things that seem to be

    Posted 11-03-2016 08:31
    Why is it always the simple things that seem to be the hardest? I have a script that I want to run when users delete Sales Order lines. The script should check to see if a UDF is blank and if it is, write a value to the UDF and then complete the delete. Is this possible? or is the pre-delete event already too far deleted to write new values? a bit of script: cancelreason = """" retVal = oBusObj.GetValue(""UDF_CANCEL_REASON$"",cancelreason) if cancelreason = """" then retVal = oBusObj.SetValue(""UDF_CANCEL_REASON$"", ""Out of Stock"") end if Any help is appreciated!


  • 2.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 08:34
    You didn't close quotes on your SetValue UDF...


  • 3.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 08:37
    That's what I get for retyping the script instead of copy/paste. I confirmed that in my actual script it is closed. Thanks for spotting that but I'm still not getting the cancel reason to write before the line is deleted. :(


  • 4.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 08:46
    What's the RetVal for the SetValue command? Is it successful? There may not be an implicit write (to put the value into SO History).


  • 5.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 08:50
    I get a ""1"" for the setvalue command. Which always makes me hopeful but still no values in SO History.


  • 6.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:12
    So when they delete a Sales Order line, it should write into a header UDF? If the Pre-Delete is at the line level, then oBusObj would be too.


  • 7.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:12
    If I'm following, it should be oHeaderObj.


  • 8.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:13
    Hi Steve! The UDF is actually on the SO_SalesOrderDetail table. So oBusObj should be the right call - right?


  • 9.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:17
    OK, so you're writing back to the line that you're deleting (and assuming, saving those in history). Are you oBusObj.Write() after that snippet of code?


  • 10.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:18
    Have you tried adding an oBusObj.write()...? My guess is that updating the value in memory in a pre-delete script won't get written to history automatically... but you may be able to force the write before the delete is processed.


  • 11.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:21
    Maybe it's not returning an empty space. You could also Trim cancelreason and then check the Length of it to see if its zero.


  • 12.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:23
    I added the write() and the reval is 1 but it still just doesn't show up. A few days ago I had another script that I created to try and write the value directly to the history table and even though it successfully found the record, it kept coming back ""the record has not been modified"". I will try the trim value and see what that does!


  • 13.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:28
    I took out where I was checking if the cancel reason was blank, but still no entry to the history table. I also added a line to write the same ""out of stock"" value to the comment text of the line detail just to make sure my UDF wasn't broken but I'm not seeing the value there either.


  • 14.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:30
    oBusObj.Write() oHeaderObj.Write() ?


  • 15.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:31
    oBusObj.Write() as the UDF is on the lines tab, and the script is running on SO_SalesOrderDetail.PreDelete...


  • 16.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:33
    I'm thinking the line write only updates memory, but the change only truly updates the record when the header is written. Think about a normal line write script. It doesn't get saved until the user clicks Accept.


  • 17.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:42
    I added the oHeaderObj.Write() but I'm still not seeing the values and history and fails to actually delete the line. so weird!


  • 18.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:48
    I once tried to write to BR during an SO Sales Journal batch, and it corrupted the process of SO's being updated... presumably because I did a Write command in the script. Anything unusual seems to throw things off. Perhaps if there is a UI, you could SetError and force the user to enter something?


  • 19.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:52
    Would priority have anything to do with this? I tried setting the priority to 001 and then to 999 because I'm not sure when the line actually is removed but I didn't see any change. Setting the error does work, but these users were really hoping to avoid a prompt. my back pocket course of action is to write to a UDT (because that works as part of the pre-delete) and then use good old VI to populate the history table. Thank you both @KevinMoyes and @SteveIwanowski for helping me!


  • 20.  RE: Why is it always the simple things that seem to be

    Posted 11-03-2016 09:54
    Priority sets the relative order with multiple scripts on the same event trigger (when compiling into a .vbs).