GetEditKey for Lines is not returning a value on a new order only

Sage 100 Standard 2015

I have this script in Sales Order.  We have a custom panel with some Header UDF's and when the user selects a line, it copies the LineKey into a header UDF to be retrieved by this script to update the Line with new UDF values.  It works great if you save a Sales Order, then edit a line.  But when creating a new Sales Order that has not yet been saved, the GetEditKey method does not appear to work.  Is there a different method I should use for a new Sales Order?

sEditKey = oLines.GetEditKey(sLineKey)                                                    'returns a full EditKey value when editing a line in a sales order that has already been saved
msgbox "linekey: " & sLinekey & " editkey: " & sEditKey                              'sLineKey returns the correct value, sEditKey returns 0
retVal = oLines.EditLine(sEditKey)                                                              'retVal = 2 and creates a new line instead of editing the existing line
'retval = oLines.EditLine(sLineKey & sLineSeq)                                            'my attempt to bypass the GetEditKey method, same results, both variables have correct values
msgbox retval
retVal = oLines.SetValue("ItemCode$", sItemCode)
If retVal = 1 Then
retVal = oLines.SetValue("ItemCodeDesc$", sDescription)
retVal = oLines.SetValue("UDF_LINE_COLOR$", sColor)
retVal = oLines.SetValue("UDF_LINE_STRAP_SPACE$", sStrap)
retVal = oLines.SetValue("UDF_LINE_OVERLAP$", sOverlap)
retVal = oLines.SetValue("UDF_LINE_PRICE_PER_SQ_FT", nUnitPrice)
retVal = oLines.SetValue("UDF_LINE_TOT_MAT_PRICE", nTotalPrice)
retVal = oLines.SetValue("UDF_LINE_FIT_TYPE$", sFit)
retVal = oLines.SetValue("UDF_LINE_FOLD_TYPE$", sFold)
retVal = oLines.SetValue("UDF_LINE_MATERIAL$", sMaterial)
retVal = oLines.SetValue("UDF_LINE_OPTION1$", sOption1)
retVal = oLines.SetValue("UDF_LINE_OPTION1_QTY", nOption1Qty)
retVal = oLines.SetValue("UDF_LINE_OPTION1_NOTES$", sOption1Notes)
retVal = oLines.Write()

Elliott, are you there?  :)

Thanks, Hollie

Parents Reply Children
  • 0 in reply to jepritch
    I grab the SOLineKey on PostRead of the line and use SetValue to put it in a header UDF. That works. The user is then directed to a custom panel with all of the Header UDF's to update, some of which are mirrored on the lines. This script is called from a button, which is supposed to update the line UDF's with the values the user selected on the panel. If the line has already been written to memory, why wouldn't I be able to grab the editKey and update it?
  • 0 in reply to hyanaga
    Hi Hollie,

    So it's only certain types of lines that you would do this for? Does the Header UDF that contains the LineKey have a concatenated list of these line keys? Do these Header UDF values apply to all the lines?

    E
  • 0 in reply to jepritch
    I don't think I explained it well. Every time the user selects a line, it re-writes just that line's LineKey to the header UDF so we know what line they want to edit. All changes made to the UDF's are then applied to just that line when we click the button to update it. I verified that it is capturing the LineKey correctly, and when I use the GetEditKey() method with it on an existing sales order, it returns a long EditKey. And it updates the line correctly.

    It's kind of a mini-configurator. There are a multitude of options, all in header UDF's. Some are order specific, some are line specific so they have mirror UDF's on the line. For example, the user configures an item and selects all the options, and for the Color UDF, selects Red, adds it to the new order with the Add button. This creates the line on the order and redirects him to the Lines tab. Then he realizes that he selected the wrong color, so he selects the line, Post-Read script copies the LineKey, he is directed to the custom panel, selects the new Color, then clicks the Update button, which is supposed to update the Color Line UDF field for just that line.

    So this is going to be a problem for us if the GetEditKey method won't allow us to edit a line on a sales order that hasn't been saved yet, because this could happen...
  • 0 in reply to hyanaga

    Maybe I'm missing something, but if you're triggering a script from a line trigger, you don't need to get the line key. The current business object is that line.

    Edit:

    Oh, it's a button script.  Maybe add a dummy checkbox UDF for a trigger (column post validate?) to refresh the data, with a different script than the "Add" button.

  • 0 in reply to hyanaga

    So, the workflow would be to always select a Row first?  If that's the case why not just retrieve the key all the time from the selected row.  This should work whether it's a new order or an existing one.

    So on your script of the Post-Read of Sales Order Detail event of the lines you are retrieving just the LineKey field currently I'm assuming, something like:

    retVal = oBusObj.GetValue("LineKey$", sLineKey)

    retVal = oHeaderObj.SetValue("UDF_LineKey$", sLineKey)

    Instead just switch to store the entire key (you may have to re-add the header UDF so it's large enough)

    sLineKey = ""

    sLineKey = oBusObj.GetKey()

    retVal = oHeaderObj.SetValue("UDF_LineKey$", sLineKey)

     

    Then in your script above instead of doing GetEditKey(sLineKey) just directly edit the line, becase the sLineKey will have everything.

    retVal = oLines.EditLine(sLineKey)

    Hopefully, that made sense.  Let me know if I've completely missed the boat.  But, if all your workflow is within the order itself, meaning you select a line then go to another tab and fill out info and press a button to launch a script, this should work.  The primary use for using GetEditKey() is when all you have is the order # and line key to go by.

    Elliott

  • 0 in reply to jepritch
    Elliott, you really get me. That's exactly what I was doing, and I didn't realize I could use the GetKey() method there. I made the changes you suggested and it works perfectly.

    Once again you have saved the day. I am going to make it to Sage Summit next year (finally in Chicago!!) and I hope you will be there so I can shake your hand and thank you for all the help you give us!

    Thanks, Hollie