The GPConnection object is used in scripts instead of the RetreiveGlobals dynamic link library that was used in Microsoft Dynamics GP 9.0 and previous versions.
The Open method allows you to open an ADO connection using the current GP user login information.This method uses the data source that is in use when Microsoft Dynamics GP is open. If you want to use a default company database (TWO or GPDAT) for this method, then you must set the Open value in the connection string before using the Open method. You will not be able to update the connection string after the Open method is called. There is no close method for this object. Once the connection is returned to the same way the connection object was initially created in the script, that connection object can be closed normally.
Syntax
object.Open({suppress})
Comments
All properties for the
Open method will return string
values.
Examples
The following example is
the Open script. It opens the data connection.
set MyCon = CreateObject("ADODB.Connection") MyCon.Connectionstring = "database=GPDAT" GPConnection.Open(MyCon)
The following is an example of creating the ADO record set.
set recset = CreateObject("ADODB.Recordset")
The following is an example of creating the ADO connection.
set MyCon = CreateObject("ADODB.Connection")
The following is an example of executing the update command
recset = MyCon.Execute(updatecommand )
The following is an example of closing the ADO Connection.
MyCon.Close
The following are examples of retrieving the properties exposed by the new GPConnection object.
MsgBox GPConnection.GPConnUserDate MsgBox GPConnection.GPConnInterCompanyID MsgBox GPConnection.GPConnUserID MsgBox GPConnection.GPConnUserName MsgBox GPConnection.GPConnDataSource
The UserDate property contains the current user date.
Syntax
object.UserDate
The CompanyID property contains the intercompany ID (company database ID).
Syntax
object.CompanyID
Example
The following is an
example of initializing the connection string to specify a default
database. In this case it is set to the current company. This could
be set to a constant database, such as GPDAT.
MyCon.Connectionstring = "database=" + GPConnection.GPConnInterCompanyID
The UserID property contains the current User ID.
Syntax
object.UserID
The UserName property contains the name of the current user.
Syntax
object.UserName
Example
The following is an
example of creating a string to update the customer name in the
customer master table.
updatecommand = "update RM00101 set [CUSTNAME]='IM Customer' where [CUSTNMBR]='AARONFIT0022'"
The DataSource property contains the name of the current data source that is being used in Microsoft Dynamics GP.
Syntax
object.DataSource