UDF using script

Hello Everyone

I am trying to update UDF in sales order line using script, i am not getting any error but it's not working

i am adding the the code that i am using

any kind of help will be really great

Thanks

____________________________________________________________________________________________________________
Dim x(9999)
Set fso = CreateObject("Scripting.FileSystemObject")
Set dict = CreateObject("Scripting.Dictionary")
If (fso.FileExists("E:\linetax.txt")) Then
    Set file = fso.OpenTextFile ("E:\linetax.txt", 1)
row = 0
Do Until file.AtEndOfStream
   line = file.Readline
  ' dict.Add row, line
   x(row)=line
  row = row + 1

Loop
file.Close
'Loop over it
end if
For Each line in dict.Items
  WScript.Echo line
Next
i=1
set oLines = oSession.AsObject(oBusObj.Lines)
retVal = oLines.MoveFirst()
Do Until oLines.EoF
    
    retx=oLines.SetValue("UDF_TEST$",x(i))    
    msgbox(retx)
    oLines.Write()
    i=i+1
    retVal = oLines.MoveNext()
    
Loop
oBusObj.write()

  • 0

    How are you calling this script? A button?

    You have the field you are attempting to set the value of indicated that it is a string by the "$" but you haven't specified that the variable you are writing to the field is a string. BOI is picky about string and numeric variables and values.

    Vbscript arrays are zero based so your "i" variable should start at 0 if you are after the first line assuming it isn't a header row, if it is, then 1 is fine.

    What is the retx value after the SetValue?

    You should also check for the return value from the oLines and oBusObj Write methods. You can also check the result of oLines.LastErrorMsg and oBusObj.LastErrorMsg.

  • 0 in reply to David Speck

    Hello David

    I am calling the script on the button click , and the UDF is of type string and i am writing a string back
    i am also trying read after  the first line

    retx value for  retx=oLines.SetValue("UDF_TEST$",x(i))    is 1

    i also tried

    retx is 1 for  retx = oLines.Write() 

    retx is -1 for  retVal = oLines.MoveNext()

  • 0 in reply to seshasai

    try "Do Until cBool(oLines.EOF)"