User field on Sales Order screen

SUGGESTED

Hi ALL,

There is a field called "User" on the Top right on the Sales Order Entry screen. Can we pass the values of that field from the BOI programming?

And Can please tell me that it stores into which table?

Please help me by giving hint to resolve this issue.

Thanks

SF

  • 0
    That should be the user created key in the header table, and to get human readable values for display you'll need to look up the key in sy_user.
  • 0
    This is the script I use to write out the order writers name to a UDF which displays the name of the order writer. You should be able to use the same process to get what you need.

    Sub PostValidation_CustomerNo500(column,value)

    sFirst = "" : sLast = "" : sKey= "" : sCKey = ""

    retVal = oBusObj.GetValue("UserCreatedKey", sCKey)

    Set oUser = oBusObj.AsObject(oBusObj.GetChildHandle("UserCreatedKey"))

    retVal = oUser.getvalue("UserKey$",sKey)
    retVal = oUser.getvalue("FirstName$",sFirst)
    retVal = oUser.getvalue("LastName$",sLast)

    If sKey = sCKey then
    retVal = oBusObj.SetValue("UDF_FIRST$", sFirst)
    retVal = oBusObj.SetValue("UDF_LAST$", sLast)

    end if
  • 0 in reply to Kevin M

    If you are only after the name of the user who created the record, you can use the GetChildHandle method (don't add a dollar sign after string columns, it just takes the column name). This will give you handle to the service object and it will be on the current record, ie if the UserCreatedKey is 0000000006 then the service object will be on that record and you can use the GetValue method to read whatever field you are after.

    set oUser_Svc = oSession.AsObject(oBusObj.GetChildHandle("UserCreatedKey"))
    sUserName = ""
    retval = oUser_Svc.GetValue("UserLogon$",sUserName)
    retval = oSession.AsObject(oSession.UI).MessageBox("", "User Name: " & sUserName)

    If you are after the name of the user who last update the record, you will need to get the value for the UserUpdatedKey then use the Find method on the child handle or get your own handle to the SY_User_Svc object. If you use the child handle, make sure you do another Find on the user created key so the UI won't display a different value since you changed the current record when using Find on the UserUpdatedKey value if it is different then the UserCreatedKey.

    sUserCreatedKey = ""
    retval = oBusObj.GetValue("UserCreatedKey$", sUserCreatedKey)
    sUserUpdatedKey = ""
    retval = oBusObj.GetValue("UserUpdatedKey$", sUserUpdatedKey)
    set oUser_Svc = oSession.AsObject(oBusObj.GetChildHandle("UserCreatedKey"))
    retval = oUser_Svc.Find(sUserUpdatedKey)
    if retval = 1 then
    sUserName = ""
    retval = oUser_Svc.GetValue("UserLogon$",sUserName)
    retval = oSession.AsObject(oSession.UI).MessageBox("", "User Name: " & sUserName)
    end if
    retval = oUser_Svc.Find(sUserCreatedKey)
    set oUser_Svc = nothing

    Reply back if you have any questions about the above code.

    Final note, both my script and BigLouie's script use the syntax for BOI executed internally, like from a button executing on the server or a user defined script. I recall in another one of your posts, you were executing externally so you will have to add the "s","n", or "o" before each method and property to identify what kind of value is being returned.

  • 0 in reply to BigLouie

    I had this script running in Sage 2014 and 2018.  Now, I recently updated to 2022.1, and it does not work. 

    In BigLouie's script, sCKey has a 10 digit value, but sKey is Null.  sKey comes from the GetChildHandle call, so I worry that there is a field that was renamed or something changed in that table.  I think the table should be SY_User_SVC, but I seem incapable of finding or reading what should be called here.  The 'sFirst' is also null.  I did not pull sLast into a message box to see it, but I figure the other two values are null, that would be also. 

    Has anyone dealt with this?  Can you lead me to 1. ideally a fix to the script or 2. a way to see what the field would be called in the child handle?  

    Thank you,

    Chris

  • 0 in reply to Beevet
    SUGGESTED

    I figured this out thanks to this post by Kevin M, who credited David Speck: 

    https://www.sagecity.com/us/sage100_erp/f/sage-100-business-object-interface/174328/pre-totals-script---accessing-item-information-using-olines-getchildhandle-itemcode/445343#445343

    The trick was to add a ReadAdditional call before calling the child handle.  I added one line, which was

    retVal = oBusObj.ReadAdditional("UserCreatedKey")

    immediately before 

    Set oUser = oBusObj.AsObject(oBusObj.GetChildHandle("UserCreatedKey"))

    Now the UDFs for names are filled.  

    I do not know why this was needed.  I did find the SY_USER table in MAS_System folder.  Everything looked like it was supposed to, there were no name changes or anything else obvious to me.  I suspect something changed in the underlying Sage code that is now different that requires this call? 

    Thank you for considering this. 

    Chris

  • 0 in reply to Beevet

    I've found the ReadAdditional is most useful when it comes to objects that have multiple fields linked to the reference table.  UserCreatedKey and UserUpdatedKey both link to SY_User.  (And in an SO Line, SalesAccountKey and CostOfGoodsSoldAccountKey both link to GL_Account).  The ReadAdditional ensures you are grabbing the right handle.

  • 0 in reply to Kevin M

    Why does this script work ok in older versions but not in 2022?  Is there something that changed or was this script just getting away with something?  

    Thank you for the explanation you provided of the ReadAddidional, this helps as I am trying to learn

    Chris

  • 0 in reply to Beevet

    I don't know of anything specific, but generally speaking, with new versions Sage often adds new features, requiring changes to the code behind the scenes.  That's why enhancements need to be verified as compatible with all Sage updates (versions, PU, hotfixes...). While it is much less common to require script updates with new versions, it can happen.