Microsoft Dynamics AX Support

This blog contains posts by the Microsoft Dynamics AX Support Teams Worldwide

Calling the BudgetTransactionService on AX 2012

We recently had a request for an example of how to call the BudgetTransactionService AIF create operation which allows you to created budget register entries.

Setup: Create an inbound AIF port using the first 10 steps (Setup with AX) from the Budget entries import in AX2012 (http://blogs.msdn.com/b/axsupport/archive/2012/11/16/budget-entries-import-in-ax2012.aspx) to create a NetTcp AIF inbound port. Create a new C# console application project in Visual Studio, adding a service reference to the AIF inbound port you created. My project was named BudgetTransactionServiceExample and my service reference was named BudgetService. The following code creates one register for FY2015 with one budget line, including only the required fields.

 

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Add a using statement for the service reference.
using BudgetTransactionServiceExample.BudgetService;

namespace BudgetTransactionServiceExample
{
class Program
{

static void Main(string[] args)
{
// Calling the create operation.
CreateOperation();
}

private static void CreateOperation()
{
// Instantiate an instance of the service client class.
BudgetTransactionServiceClient service = new BudgetTransactionServiceClient();

CallContext context = new CallContext();
context.Company = "usmf";

// Create an instance of the document class.
AxdBudgetTransaction bTran = new AxdBudgetTransaction();

// Create instances of the entities that are used in the service and
// set the needed fields on those entities.
AxdEntity_BudgetTransHeader bHeader = new AxdEntity_BudgetTransHeader();
bHeader.BudgetModelId = "FY2015";
bHeader.BudgetTransactionCode = "Original Budget";
bHeader.PrimaryLedger = "usmf";

AxdType_DimensionAttributeValue dimVal = new AxdType_DimensionAttributeValue();
dimVal.Name = "MainAccount";
dimVal.Value = "401100";

AxdType_BudgetAccount bAccount = new AxdType_BudgetAccount();
bAccount.DisplayValue = "Manufacturing Profit and Loss";
bAccount.AccountStructure = "Manufacturing P&L";

AxdEntity_BudgetTransLine bLine = new AxdEntity_BudgetTransLine();
bLine.TransactionCurrency = "USD";
bLine.LedgerDimension = bAccount;

// Add the sub-entity instances to their parent entities as an array
// of the sub-entity type.
bAccount.Values = new AxdType_DimensionAttributeValue[1] { dimVal };
bHeader.BudgetTransLine = new AxdEntity_BudgetTransLine[1] { bLine };
bTran.BudgetTransHeader = new AxdEntity_BudgetTransHeader[1] { bHeader };

try
{
// Call the create method on the service passing in the document.
var ret = service.create(context, bTran);

// The create method returns an EntityKey which contains the IDs for the budget register.
Console.WriteLine("Create successful. {0}:{1} {2}:{3}", ret[0].KeyData[0].Field, ret[0].KeyData[0].Value, ret[0].KeyData[1].Field, ret[0].KeyData[1].Value);
}
catch (Exception e)
{
Console.WriteLine("Create failed.");
Console.WriteLine(e.Message);
}
finally
{
Console.ReadLine();
}
}

}
}
  

Notice:

“Microsoft provides programming examples for illustration only, without warranty expressed or implied, including, but not limited to, the implied warranties of merchantability or fitness for a particular purpose. This mail message assumes that you are familiar with the programming language that is being demonstrated and the tools that are used to create and debug procedures.”

This has not been officially tested by Microsoft and should be fully tested before implementation.