Error LastErrorNum and Msg: CI_Required:The Sales Order Number is required when saving UDF changes to SO Header record.

We are exporting Sales Orders to a distribution center for shipping. I have created 2 UDFs on the SO_SalesOrderHeader table. Once the export file is done, I have a script that reads through it and is trying to update the 2 header UDFs.  When I go to save the changes .nWrite(), I get the following message:

LastErrorNum - CI_Required     

LastErrorMsg - The Sales Order Number is required.

And the retVal from the .nWrite command is blank

However, looking into the SO_SalesOrderHeader table, the 2 UDFs have been updated for the desired SO

Here is the code:

SoH is the Sales Order header object

        retVal = SoH.nSetKeyValue("SalesOrderNo$",strOrderNo)
        If retVal = 1 Then
            LogMessage = CurrentDate & " " & CurrentTime & " - SetKeyValue OK for SO Number: " & strOrderNo
        Else
            LogMessage = CurrentDate & " " & CurrentTime & " - LastErrorNum and Msg: "  & SoH.sLastErrorNum & ":" & SoH.sLastErrorMsg
            LogMessage = CurrentDate & " " & CurrentTime & " - Actual Length of strOrderNo is: " & CStr(Len(strOrderNo))
        End If

        retVal = SoH.nSetKey()
        If retVal = 1 Then

            'found the SO, so update the UDFs
            retVal = SoH.nSetValue("UDF_EXPORTED2DC$", "Y")
            retVal = SoH.nSetValue("UDF_EXPORTED_DT$", CurrentDate & " : " & CurrentTime)
            retVal = SoH.nWrite()

            If retVal <> 1 Then
                LogMessage = CurrentDate & " " & CurrentTime & " - LastErrorNum and Msg: "  & SoH.sLastErrorNum & ":" & SoH.sLastErrorMsg & " retVal: " & CStr(retVal)

            End If

     .... More addition code here to loop through the remaining Sales Orders that are in the export file.

The highlighted LogMessage produces the following message:  20210923 15:17 - LastErrorNum and Msg: CI_Required:The Sales Order Number is required. retVal:

After this message is received, any other attempts to do anything with the SoH object just stops script execution and throws an Error 0 message