Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error running vb script

Status
Not open for further replies.

Luvsql

Technical User
Apr 3, 2003
1,179
CA
I have included the following vb script to the Distribution Account on a receivable transaction integration. It is failing with the error "DOC 1 ERROR: Source Field Source1.F5' not found in object."

This is the correct Source name and the correct Source column (doesn't have headers). Can I reference another source even when the Record Source under options for the Distributions is set to Source2?

'This script is intended to:
' 1. Read the default GL A/R account associated with the customer
' 2. Use A/R account for distribution type 3 and source for other types.

sDataSourceName="GreatPlains"
sLogin="user"
sPassword="password"
sDatabaseName="DB"
sCustomerARFieldName="RMARACC"
sCustomerID=SourceFields("Source1.F5")

'Open a connection to the SQL database
Set pConnection = CreateObject("ADODB.Connection")
Call pConnection.Open(sDataSourceName, sLogin, sPassword)

'Create a new recordset -- that will hold returned data
Set pRecordset = CreateObject("ADODB.Recordset")

'Create a SQL SELECT statement to retrieve the customer's default
'AR account number
sSQL = "SELECT Rtrim(ACTNUMST) 'ARAccount'"
sSQL = sSQL & " FROM " & sDatabaseName & ".dbo.RM00101, "
sSQL = sSQL & sDatabaseName & ".dbo.GL00500 WHERE "
sSQL = sSQL & "RM00101.CUSTNMBR= '" & sCustomerID & "'"
sSQL = sSQL & " AND RM00101." & sCustomerARFieldName
sSQL = sSQL & "=GL00105.ACTINDX"

Call pRecordset.Open(sSQL, pConnection, 3, 1)
sARAccount=pRecordset("ARAccount")
Call pRecordset.Close
Call pRecordset.Open(sSQL, pConnection, 3, 1)
sARAccount=pRecordset("ARAccount")
Call pRecordset.Close

If SourceFields("Source2.F4")=3 THEN
CurrentField=ARAccount
Else CurrentField=("Source2.F3")
End If
 
I've tried another way of doing this. I added this code to the Before Document Commit:

If SourceFields("Source2.F4")=3 then
DestinationFields("Distribution.Distribution Account")=.SetToDefault
Else DestinationFields("Distribution.Distribution Account")=("Source2.F3")
End If

My error is now "non-alpanumeric characters were found in the 'Distribution Account' field of the 'Distribution' recordset. The account number column in the source is setup as string and it runs fine without the script ie it imports the account numbers fine when it is set to use source. Why does it import an account in the format xxx-xxxx-xxx when using the regular use source rule, but fails when adding a before doc commit with the same data?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top