CreateGLTransaction


Description

This method creates a new GL transaction.

Parameters

Parameter

Type

Description

glTransaction

GLTransaction

The GL transaction being created.

context

Context

Specifies information about how the method will be called.

policy

Policy

Specifies the set of behaviors and behavior options to be applied during the operation.


Interfaces

 

Examples

The following C# example creates a GL transaction. The example uses a GL transaction key to identify the new transaction. The batch key and reference property are also populated and two GL transaction line objects are created to specify the GL accounts and the transaction amount. All other properties are left as default values.

 Legacy endpoint

using System;
using System.Collections.Generic;
using System.Text;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			BatchKey batchKey;
			GLTransactionKey transactionKey;
			GLTransaction transaction;
			GLTransactionLineKey glTransactionLineKey;
			GLTransactionLine transactionDebitLine;
			GLTransactionLine transactionCreditLine;
			GLAccountNumberKey debitAccountKey;
			GLAccountNumberKey creditAccountKey;
			MoneyAmount debitAmount;
			MoneyAmount creditAmount;
			MoneyAmount zeroAmount;
			Policy transactionCreatePolicy;

			// Create an instance of the service
			DynamicsGP wsDynamicsGP = new DynamicsGP();

			// Be sure the default credentials are used
			wsDynamicsGP.UseDefaultCredentials = true;

			// Create a context with which to call the service
			context = new Context();

			// Specify which company to use (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Set up the context object
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create a batch key object to specify the batch
			batchKey = new BatchKey();
			batchKey.Id = "RMCSH00000011";

			// Create a GL transaction key object to identify the transaction
			transactionKey = new GLTransactionKey();
			transactionKey.JournalId = 3365;
			transactionKey.Date = new DateTime(2007, 4, 12);

			// Create the transaction object
			transaction = new GLTransaction();

			// Populate the GL transaction object's key property
			transaction.Key = transactionKey;

			// Populate the batch key and reference properties 
			transaction.BatchKey = batchKey;
			transaction.Reference = "Receivables Cash Receipts";

			// Create a GL transaction line key
			glTransactionLineKey = new GLTransactionLineKey();

			// Create two GL transaction lines:
			// Create the debit transaction line
			transactionDebitLine = new GLTransactionLine();

			// Populate the transaction line key
			transactionDebitLine.Key = glTransactionLineKey;

			// Create a GL account number key object to specify the account
			debitAccountKey = new GLAccountNumberKey();
			debitAccountKey.Id = "000-1100-00";

			// Populate the debit line GL account key property
			transactionDebitLine.GLAccountKey = debitAccountKey;

			// Create a money object
			zeroAmount = new MoneyAmount();
			zeroAmount.Value = 0m;
			zeroAmount.Currency = "USD";

			// Create a money object for the debit amount
			debitAmount = new MoneyAmount();
			debitAmount.Value = 50m;
			debitAmount.Currency = "USD";

			// Populate the transaction line debit and credit amount properties
			transactionDebitLine.DebitAmount = debitAmount;
			transactionDebitLine.CreditAmount = zeroAmount;
					
			// Create the credit transaction line
			transactionCreditLine = new GLTransactionLine();

			// Populate the transaction line key
			transactionCreditLine.Key = glTransactionLineKey;

			// Create a GL account number key object to specify the account
			creditAccountKey = new GLAccountNumberKey();
			creditAccountKey.Id = "000-1200-00";

			// Populate the credit line GL account key property 
			transactionCreditLine.GLAccountKey = creditAccountKey;

			// Create a money amount object for the credit
			creditAmount = new MoneyAmount();
			creditAmount.Value = 50m;
			creditAmount.Currency = "USD";

			// Populate the transaction line debit and credit amount properties
			transactionCreditLine.DebitAmount = zeroAmount;
			transactionCreditLine.CreditAmount = creditAmount;

			// Create an array to hold the two GL transaction line objects
			GLTransactionLine[] lines = { transactionDebitLine, transactionCreditLine };

			// Add the array of GL transaction line objects to the transaction object
			transaction.Lines = lines;

			// Get the create policy for GL transactions
			transactionCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateGLTransaction", context);

			// Create the GL transaction
			wsDynamicsGP.CreateGLTransaction(transaction, context, transactionCreatePolicy);
	}
}
}

 Native endpoint

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			BatchKey batchKey;
			GLTransactionKey transactionKey;
			GLTransaction transaction;
			GLTransactionLineKey glTransactionLineKey;
			GLTransactionLine transactionDebitLine;
			GLTransactionLine transactionCreditLine;
			GLAccountNumberKey debitAccountKey;
			GLAccountNumberKey creditAccountKey;
			MoneyAmount debitAmount;
			MoneyAmount creditAmount;
			MoneyAmount zeroAmount;
			Policy transactionCreatePolicy;

			// Create an instance of the service
			DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

			// Create a context with which to call the service
			context = new Context();

			// Specify which company to use (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Set up the context object
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create a batch key object to specify the batch
			batchKey = new BatchKey();
			batchKey.Id = "RMCSH00000011";

			// Create a GL transaction key object to identify the transaction
			transactionKey = new GLTransactionKey();
			transactionKey.JournalId = 3365;
			transactionKey.Date = new DateTime(2007, 4, 12);

			// Create the transaction object
			transaction = new GLTransaction();

			// Populate the GL transaction object's key property
			transaction.Key = transactionKey;

			// Populate the batch key and reference properties 
			transaction.BatchKey = batchKey;
			transaction.Reference = "Receivables Cash Receipts";

			// Create a GL transaction line key
			glTransactionLineKey = new GLTransactionLineKey();

			// Create two GL transaction lines:
			// Create the debit transaction line
			transactionDebitLine = new GLTransactionLine();

			// Populate the transaction line key
			transactionDebitLine.Key = glTransactionLineKey;

			// Create a GL account number key object to specify the account
			debitAccountKey = new GLAccountNumberKey();
			debitAccountKey.Id = "000-1100-00";

			// Populate the debit line GL account key property
			transactionDebitLine.GLAccountKey = debitAccountKey;

			// Create a money object
			zeroAmount = new MoneyAmount();
			zeroAmount.Value = 0m;
			zeroAmount.Currency = "USD";

			// Create a money object for the debit amount
			debitAmount = new MoneyAmount();
			debitAmount.Value = 50m;
			debitAmount.Currency = "USD";

			// Populate the transaction line debit and credit amount properties
			transactionDebitLine.DebitAmount = debitAmount;
			transactionDebitLine.CreditAmount = zeroAmount;
					
			// Create the credit transaction line
			transactionCreditLine = new GLTransactionLine();

			// Populate the transaction line key
			transactionCreditLine.Key = glTransactionLineKey;

			// Create a GL account number key object to specify the account
			creditAccountKey = new GLAccountNumberKey();
			creditAccountKey.Id = "000-1200-00";

			// Populate the credit line GL account key property 
			transactionCreditLine.GLAccountKey = creditAccountKey;

			// Create a money amount object for the credit
			creditAmount = new MoneyAmount();
			creditAmount.Value = 50m;
			creditAmount.Currency = "USD";

			// Populate the transaction line debit and credit amount properties
			transactionCreditLine.DebitAmount = zeroAmount;
			transactionCreditLine.CreditAmount = creditAmount;

			// Create an array to hold the two GL transaction line objects
			GLTransactionLine[] lines = { transactionDebitLine, transactionCreditLine };

			// Add the array of GL transaction line objects to the transaction object
			transaction.Lines = lines;

			// Get the create policy for GL transactions
			transactionCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateGLTransaction", context);

			// Create the GL transaction
			wsDynamicsGP.CreateGLTransaction(transaction, context, transactionCreatePolicy);

			// Close the service
			if(wsDynamicsGP.State != CommunicationState.Faulted)
			{
				wsDynamicsGP.Close();
		}
	}
}
}


Documentation Feedback