Quantcast
Channel: Microsoft Dynamics 365 Support
Viewing all articles
Browse latest Browse all 840

Calling the BudgetTransactionService on AX 2012

$
0
0

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
{
classProgram
{

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

privatestatic void CreateOperation()
{
// Instantiate an instance of the service client class.
BudgetTransactionServiceClient service = newBudgetTransactionServiceClient();

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

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

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

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

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

AxdEntity_BudgetTransLine bLine = newAxdEntity_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 = newAxdType_DimensionAttributeValue[1] { dimVal };
bHeader.BudgetTransLine = newAxdEntity_BudgetTransLine[1] { bLine };
bTran.BudgetTransHeader = newAxdEntity_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.


Viewing all articles
Browse latest Browse all 840

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>