User Defined Scripting

I have created a JobNumber UDF and added it to AR and AP invoice data entry line detail.  Now I would like to create a User Defined Script for the actual Job Number entered during data entry to be written to the JobNumber UDF.  In AR it comes from the header and in AP it comes from the line detail.  The script that I wrote checks out, but it throws an error 88 when I try to enter an invoice.  Any help will be most appreciated!

Thanks in advance.

  • 0 in reply to jsmith2

    Now put this after each the getvalue and setvalue lines to see which line and what error is actually happening.

    retval = oSession.AsObject(oSession.UI).Messagebox( "This is the jobno retrieved ->" & JobNo   &   "  Error message if any "  & oBusObj.LastErrorMsg)

    BTW what event are you attaching the script to?  Column - post validate for the JobNo field is probably the best bet.

  • 0 in reply to TomTarget

    The event is Table-Set Default Values.  

    So here is the crazy thing... I added the lines to the script as you suggested.  And I changed the event to Column - Post Validate.  Then I decided I should try one thing at a time.  So I deleted the event and reentered Table-Set Default Values.  When I retested, the Job Number populated!  And with no error reporting.  So I removed the added lines from the script, changed the event to Column - Post Validate and tested that.  It worked, as well.

    I wonder if there was some sort of glitch in the original Event setup that wasn't getting read properly.  By deleting it and recreating it, it appears to work now!

    Since both Table-Set Default Values works, do you think Column - Post Validate is still the best bet?  

    Thanks so much for all your help!  

  • 0 in reply to jsmith2

    Column - Post Validate is the correct option.

  • 0 in reply to jsmith2

    To be perfectly honest - I have no clue why Table-Set Default Values would work?   In theory that would fire before you even entered your job number.   I'm guessing that when you recompiled your script you were already in the data entry window.   Seems like a recompiled script doesn't take effect until you exit the data entry and come back in.

    I would stick with Column - Post Validate.

  • 0 in reply to TomTarget

    You have been a great help!!!!  Thanks so much.  One more question.  My script works great for AP.  Now I  have moved on to AR nvoice data entry.  My dilemma...now  I am pulling the JobNo from the Header record to the Line detail record and I think I have to modify my script.  I assume I use oHeaderObj?  Suggestions on how to modify my script?  

  • 0 in reply to jsmith2

    I believe you are on the right track using oHeaderObj.

    The biggest thing you should have learned from this is using the message boxes to show you results and help you figure out where the problems are (is the script running?  where is an error being thrown?  when am I getting results that don't make sense?   etc.).

    Believe me,  without those techniques I would be totally lost.   It's pretty rare for me to not make some silly mistake when I write a script including most of the ones you made in this process.

  • 0 in reply to jsmith2

    Funny... my scripting doesn't seem like rocket science and I feel ridiculous struggling so!  

    I am taking your recommendation and the script is firing.  But I am getting an error when it reads the Header object:  "This is the jobno retrieved ->WMC1599  Error message if any "WMC1599" is not numeric.:"   Then when it is supposed to write to the Line UDF, this is the error:  "This is the jobno retrieved ->WMC1599  Error message if any The 0000079IN00000100000000000001 is invalid.:"

    Unfortunately, I do not know what these errors mean.

    The script is firing and it reads a valid Job Number and my UDF is a string, so I not sure why the header record information would be invalid... it is only supposed to copy the Job Number from the header to the Job Number UDF on the line detail.  

    retval = oSession.AsObject(oSession.UI).Messagebox("Script Fired")

    retVal = 0

    JobNo = ""

    retVal = oHeaderObj.GetValue("JobNo$",JobNo)

    retval = oSession.AsObject(oSession.UI).Messagebox( "This is the jobno retrieved ->" & JobNo   &   "  Error message if any "  & oHeaderObj.LastErrorMsg)

    retVal = oBusObj.SetValue("UDF_JOB_NUMBER_UDF$",JobNo)

    retval = oSession.AsObject(oSession.UI).Messagebox( "This is the jobno retrieved ->" & JobNo   &   "  Error message if any "  & oBusObj.LastErrorMsg)

  • 0 in reply to jsmith2

    retVal=oHeaderObj.GetValue("Field Name$",JobNo)

    retVal=oBusObj.SetValue("Field Name$",JobNo)

  • 0 in reply to BigLouie

    Big Louie:

    Isn't that what I have?  Please let me know what I am missing...  (the extra lines were for error messaging... they are what produced the messages that were supposed to help me figure out where my scripting is wrong.  

    retVal = 0

    JobNo = ""

    retVal = oHeaderObj.GetValue("JobNo$",JobNo)

    retVal = oBusObj.SetValue("UDF_JOB_NUMBER_UDF$",JobNo)

  • 0 in reply to jsmith2

    ??  Are you working in A/R or A/P right now?   The second error is suggesting you might be in A/R based on the value with the IN in it.   However other things make me think you are working with A/P?

    What data table and data field have you a attached the event to?   And what event are you using to trigger?

    If you are using oHeaderObj that assumes the event is tied to the detail line file.  

    Also confirm that your user defined field is defined with the correct data type.

    ---

    Note that scripting is not rocket science (or just programming in general),  but neither is it for the faint of heart.   Experience is key and it just takes a little while.  I still struggle at times.    Keep at it.  :)