BOI to update the PO Lines from an external data source

Hi Forum,

I need to write a BOI script to update a PO Line UDF from an external Data Source.

My question is, how can i get the line to update the UDF, i wrote a little script to update the line but i get the message that the o.oLines is in read only mode.

I don't know if i need to set the PO header before looping thru the lines.

I never done this type of script.  I have the following ...

' Set the company, module date and module for the Session
r = oss.nsetcompany("ABC")
'r = oSS.nSetDate("P/O",mdate) giving invalid date
r = oSS.nSetDate("P/O",oSS.sSystemDate)
r = oSS.nSetModule("P/O")
strcsinitials = "": strcsinitials = oSS.sUserCode

' Instantiate a Sales Order business object
oSEC = oSS.nSetProgram(oSS.nLookupTask("PO_PurchaseOrder_ui"))
Set o = oScript.NewObject("PO_PurchaseOrder_bus", oSS)

'Setup the instance of the Lookup file

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objFile = objFSO.OpenTextFile("C:\K-Four Customers\AKDO\JASON Scripts\trackinglist.csv", ForReading)
Set objFile = objFSO.OpenTextFile("C:\Apps\trackinglist2.txt", ForReading)

DO WHILE NOT CBool(o.oLines.nEOF)

r = o.oLines.nGetValue("PurchaseOrderNo$",sPONum)

If r = 0 Then
MsgBox(o.sLastErrorMsg & vbCRLF & "PO Number")
End If

'msgbox sPONum

r = o.oLines.nGetValue("LineKey$",sLineKey)
r = o.oLines.nGetValue("UDF_BOL$",sBOL)
'msgbox sBOL
if sBOL <> "" then

'MsgBox "PO Number: " & sPONum & " LineKey: " & sLineKey & " BOL#: " & sBOL

'Read GoComet file

Do While objFile.AtEndOfStream = False
strLine = objFile.ReadLine

'msgbox strLine

arrFields = Split(strLine, vbTab)
strTracking = arrFields(3)
strEvent = arrFields(9)
strETA = arrFields(12)

if strTracking <> "" then
strTracking2 = strTracking
end if

if strTracking2 = sBOL then
if strEvent ="4" then

msgbox "Tracking #: " & strTracking2 & " Event: " & strEvent & " ETA: " & strETA

r = o.nSetKeyValue("PurchaseOrderNo$",sPONum)
r = o.nFind()
msgbox sPONum
If r = 0 Then
MsgBox(o.oLines.sLastErrorMsg & vbCRLF & "...PO Number")
End If

r = o.oLines.nSetKeyValue("PurchaseOrderNo$",sPONum)
r = o.oLines.nSetKeyValue("LineKey$",sLineKey)
r = o.oLines.nSetKey()

'If r = 0 Then
MsgBox(o.oLines.sLastErrorMsg & vbCRLF & "PO Number")
'End If


'if len(strETA) < 10 then
'strETA1 = strETA&Space(10)
'strETA = "" : strETA = strETA1
'end if

'strDate = "" : strDate = strETA(4,2)&"/"&strETA(1,2)&"/"&strETA(7,4)
retVal = o.oLines.nSetValue("UDF_ETA$", strETA)

'if retVal = 0 Then
MsgBox(o.oLines.sLastErrorMsg & vbCRLF & "Setting the Line ETA")
'End If


r = o.oLines.nWrite()

If r = 0 Then
MsgBox(o.oLines.sLastErrorMsg & vbCRLF & "PO Lines")
End If

msgbox "went thru ..."

exit do

End if

End if

'End if

loop

end if

r = o.oLines.nMoveNext()

Loop

any help will be greatly appreciated ...

Regards,

Manuel Roman

  • 0

    You do need to use the header object, in this case, PO_PurchaseOrder_Bus.  You need to use the header's SetKey method to set the header into an editable state, which should set up the lines for you.  You can then loop through using the header object's oLines property.

  • 0 in reply to David Speck

    It's important also to note that using the Find() method puts the record in a read-only state as well, Find() is used for reading data primarilyl, SetKey() is used when you intend to modify or add data.  And as stated, you need to access the lines via the header object.

    You may want to consider structuring this a little differently as well, as it may not be efficient to scan through all the lines in every Purchase Order and for each line scan the entire GoComet file.

    You might want to consider building a subset of PO Lines using GetResultsSets() looking for values in your UDF _BOL field.  This way you could at least start with a list of lines that have a BOL and their corresponding P/O #'s.    You could then drive off of your GoComent file and then scan your array from the GetResultSets for the corresponding PO + Line.   Anyway, just food for thought.  Review the GetResultSets() use and see if that makes sense.

    E

  • 0 in reply to jepritch

    Thank you, i will certainly give it a try ...

    Regards,