Update existing PO lines

SOLVED

I am new to this so please bear with me. I have the following script ( i can only post a portion of the code. The SPAM blocker flagged it as malicious) that is used to update two UDF fields from a .csv file. It is called via a custom application. I am passing several parameters to the script. It works great with one exception. If the .csv has a record (PO#, LineKey) that is not already on the PO in SAGE the script is creating a new PO line. I only want it to update existing lines not create a new one. What did I do wrong? Thanks in advance.

Relevant part of the code. I posted the entire code as a PDF to get around this posting issues

poKey = sPoNum + sLkey
retChk oPOObj.oLines.nEditLine(poKey),oPOObj.oLines
retChk oPOObj.oLines.nsetValue("ItemCode$",Cstr(arrValues(2))),oPOObj.oLines
retChk oPOObj.oLines.nsetValue("UDF_STAGING$",Cstr(arrValues(5))),oPOObj.oLines
retChk oPOObj.oLines.nsetValue("UDF_PICKEDUP$",Cstr(arrValues(4))),oPOObj.oLines
retChk oPOObj.oLines.nWrite(),oPOObj.oLines

Code.pdf

  • +1
    verified answer

    You need to add a check if the line exists.  retChk will be one if the line exist, you only want to write if the line exists.

    ...

    retChk oPOObj.oLines.nEditLine(poKey),oPOObj.oLines

    If retChk =1 Then

    retChk oPOObj.oLines.nsetValue("ItemCode$",Cstr(arrValues(2))),oPOObj.oLinesretChk oPOObj.oLines.nsetValue("UDF_STAGING$",Cstr(arrValues(5))),oPOObj.oLinesretChk oPOObj.oLines.nsetValue("UDF_PICKEDUP$",Cstr(arrValues(4))),oPOObj.oLines

    retChk oPOObj.oLines.nWrite(),oPOObj.oLines

    End If

  • +1
    verified answer

    Daburke

    Thanks for the reply. If did it a bit different but followed the same logic. The nEditLine was returning a 2 (new record) yet it updated existing records and created new ones for lines that did not exist on the PO. 

    This worked for me

    sLkey = Cstr(arrValues(3))
    poKey = Cstr(sPoNum) & Cstr(sLkey)
    editKey = oPOObj.oLines.sGetEditKey(poKey)
    r = oPOObj.oLines.nEditLine(editKey)
    If r = 1 Then
    retChk oPOObj.oLines.nsetValue("ItemCode$",Cstr(arrValues(2))),oPOObj.oLines
    retChk oPOObj.oLines.nsetValue("UDF_STAGING$",Cstr(arrValues(5))),oPOObj.oLines
    retChk oPOObj.oLines.nsetValue("UDF_PICKEDUP$",Cstr(arrValues(4))),oPOObj.oLines
    retChk oPOObj.oLines.nWrite(),oPOObj.oLines
    End If

    Thanks again