torsdag den 8. november 2012

Dynamics AX 2012 Excel Add-in document services and queries with missing relatios

While working on an assignment where I among other things had to prepare a new query for use with document services and the Excel add-in.

The query consisted of three nested data sources, where two was standard tables and the third was a new table which I had added to the system.

First version worked just fine. I exposed the query through document services and I could get data in Excel.

The for some reason I decided to change the relations on the table I had added, for reasons that I forget.

However suddenly my query was not showing up in the pick list, when I using the "Dynamics AX" / Add Data button i Excel.

The reason ? I had messed up the relation from my new table to the standard table, making the relation empty.

The Excel add-in reacts by simply not showing the now invalid query in the list, but it does not warn you that something is wrong.

I got a clue to this, by trying to use "Add table" instead going directly for my new table.
Then Excel add-in showed me an error message, where it stated that something was wrong in the relation.

I proceeded to correct the table relation, and voila, my query was back in action to serve as a Document data source.

So if you experience that your query will not show up in the Excel add-in try checking that the table relations of the tables used in the query, or the relations used in the query are valid.

fredag den 20. juli 2012

Dynamics AX 2012: Error occurs when importing .xpo-file.

Note to self:
When experiencing Error occurs when importing .xpo-file in Dynamics AX 2012:

http://community.dynamics.com/product/ax/f/33/p/73381/134073.aspx

That is correct the PROJECTCLASS line in the .xpo-file by appending ProjectNode or install
hotfix for KB 2661360.

tirsdag den 8. maj 2012

Just needed to save some code I have been working on in my blog.

This code is used for basically deconstructing ledger dimensions and default dimensions to be able to merge / overwrite dimension attribute values in the ledger dimension.

My scenario is that during the processing of a ledger allocation, I have an "original" transaction that is being allocated. My destination transaction (the transaction that allocates the original transaction to a new ledger dimension) will inherit all the ledger dimensions of the original transaction BUT will have some of it's dimension attribute values overwritten, by a default dimension set up on the ledger allocation rule destination.

Basically I deconstruct the ledger dimension of the original transaction and put all the found dimensions into a map.

I the deconstruct the default dimension of the ledger allocation rule destination, and find the matching entries in my map, to replace them.

When my "merged" map is complete, I prepare a list of DimensionAttributeValueContract objects that is fed in to a LEdgerAccountContract object.

This is then used when calling DimensionsServiceProvider::BuildDimensionStorageForLedgerAccount to create a DimensionAttributeValueCombination record that can be attached on my LedgerJournalTrans record in the LedgerDimension field.



///
/// Finds or creates a DimensionAttributeValueCombination record

///

///

/// GeneralJournalAccountEntry record

///

///

/// LedgerAllocationRuleDestination

///

///

/// Recid of DimensionAttributeValueCombination record

///

///

/// Used to ensure that the correct main account / dimension combination for allocation ledgerJournalTrans are available

/// The combination is constructed using dimensions inherited from the "original" generealAccountJournalEntry record that is being allocated

/// and the default dimension of the ledgerallocationruleDestination. The dimensions from the ledgerAllocationRuleDestination overrides the

/// dimensions of the original generealAccountJournalEntry if set.

///


private recId findOrCreateDimAttrValueCombination(LedgerJournalTrans _sourceTrans,LedgerAllocationRuleDestination _ledAllocationRuleDest)


{

// These objects are used for constructing a ledgerdimension

LedgerAccountContract ledAccountContract;

DimensionAttributeValueContract dimAttrValueContract;

List dimAttrValueObjects;

Map commonAttributeMap;

MapIterator commonAttributeMapInterator;


DimensionStorage dimStorage;

// Deconstruction variables ledgerdimension

int hierachyCount,hierachyIndex;

int segmentCount,segmentIndex;

DimensionStorageSegment dimStorageSegment;

DimensionAttribute orgTransDimAttribute;

DimensionAttributeValue orgTransDimAttributeValue;


// Deconstruction variables defaultdimension for ledgerallocationruledestination

DimensionAttributeValueSetStorage dimAttrValueSetStorage;

int ruleDestCount,ruleDestIndex;

// Common attribute map object

commonAttributeMap = new Map(Types::Int64,Types::Int64);


// Construct dimensions storage object for desconstructing dimension values of original trans

dimStorage = DimensionStorage::findById(_sourceTrans.LedgerDimension);


hierachyCount = dimStorage.hierarchyCount();



// Deconstruction original trans and constructing a List of dimAttrValueContract objects that can be used for finding/creating a

// DimensionAttributeValueCombination record

for(hierachyIndex=1;hierachyIndex<=hierachyCount;hierachyIndex++)

{

segmentCount = dimStorage.segmentCountForHierarchy(hierachyIndex);

for(segmentIndex=1;segmentIndex<=segmentCount;segmentIndex++)

{

// Get segment

dimStorageSegment = dimStorage.getSegmentForHierarchy(hierachyIndex,segmentIndex);

if (dimStorageSegment.parmDimensionAttributeValueId() != 0)

{

orgTransDimAttribute = DimensionAttribute::find(DimensionAttributeValue::find(dimStorageSegment.parmDimensionAttributeValueId()).DimensionAttribute);

orgTransDimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(orgTransDimAttribute,dimStorageSegment.parmDisplayValue());

commonAttributeMap.insert(orgTransDimAttribute.RecId,orgTransDimAttributeValue.RecId);

}

}

}



// Deconstruction ledger allocation rule destination and overriding dimensionattribute values for original transaction dimension with the default dimension

// from the allocation rule destination



// Construct DimensionAttributeValueSetStorage object for deconstructing dimension values of ledgerAllocationRuleDestination

dimAttrValueSetStorage = DimensionAttributeValueSetStorage::find(_ledAllocationRuleDest.ToDefaultDimension);

ruleDestCount = dimAttrValueSetStorage.elements();


// Traverse DimensionAttributeValueSet and "override" values in common attribute map

for(ruleDestIndex=1;ruleDestIndex<=ruleDestCount;ruleDestIndex++)

{

if (commonAttributeMap.exists(dimAttrValueSetStorage.getAttributeByIndex(ruleDestIndex)))

{

// Remove dimension already gathered

commonAttributeMap.remove(dimAttrValueSetStorage.getAttributeByIndex(ruleDestIndex));

// Insert overridden dimension

commonAttributeMap.insert(dimAttrValueSetStorage.getAttributeByIndex(ruleDestIndex),dimAttrValueSetStorage.getValueByIndex(ruleDestIndex));

}

else

commonAttributeMap.insert(dimAttrValueSetStorage.getAttributeByIndex(ruleDestIndex),dimAttrValueSetStorage.getValueByIndex(ruleDestIndex));

}



// Build list of DimensionAttributeValueContract objects

// Initialize list of DimensionAttributeValueContract objects

dimAttrValueObjects = new List(Types::Class);

commonAttributeMapInterator = new MapIterator(commonAttributeMap);

// Traverse "common set" of attributes for main account

while (commonAttributeMapInterator.more())

{

// Prepare DimensionAttributeValueContract objects for DimensionServiceProvider object

dimAttrValueContract = new DimensionAttributeValueContract();



orgTransDimAttribute = DimensionAttribute::find(commonAttributeMapInterator.key());

orgTransDimAttributeValue = DimensionAttributeValue::find(commonAttributeMapInterator.value());



// Inherit dimension from original transaction

dimAttrValueContract.parmName(orgTransDimAttribute.Name);

dimAttrValueContract.parmValue(orgTransDimAttributeValue.getValue());

dimAttrValueObjects.addEnd(dimAttrValueContract);

commonAttributeMapInterator.next();

}



// Initialize LedgerAccountContract

ledAccountContract = new LedgerAccountContract();

ledAccountContract.parmMainAccount(DimensionStorage::getMainAccountFromLedgerDimension(_sourceTrans.LedgerDimension).MainAccountId);

ledAccountContract.parmValues(dimAttrValueObjects);

return DimensionServiceProvider::buildDimensionStorageForLedgerAccount(ledAccountContract).save();

}

As always - If you use this code, you do so at your own risk.

torsdag den 29. marts 2012

Mental note to self: AIF changes -> Incremental CIL build.

After using a couple of hours trying to understand why my newly created AIF-service was not doing exactly was it was supposed to do, I found the solution.

My AIF service uses a new table to accept some value from an external system.
When a record is introduced into this table, a new ledger journal with a ledger journal line is created, and the voucher the line gets in the journal line, is updated onto my new table.

This to allow for making it possible to use customized code in an AIF service, without having to make changes to the table methods of the Generel ledger journal tables and without risking custmized code made in the Service classes being overwritten by a service wizard update of the service.

I had completed and activated my service, and was testing it.
Then I discovered that I had forgotten to call the code to create the ledger journal, on my new table's insert-method, therefor I got records in my table, but no ledger journal.

So I quickly inserted the call to the method, and tested again.
Still no general journal generated. :(

After pondering this I decided to deactivated the service and try to activate som logging, to see what was going on, and then reactivate it.

And voila, now I got my general ledger journals.
The activation of my service had of course built new CIL-code.

Conclusion:

REMEMBER to ALWAYS incrementally build CIL-code, when you change ANYTHING in AX, that is used in an AIF service.

Dynamics AX 2012 annoyances (for (old school) developers).

Dynamics AX 2012 annoyances (for (old school) developers).

Sorry about the parathesis.

Having worked with Dynamics AX 2012 way back when it was called Axapta, I remember the days where the IDE had not undergone the Microsoft transition of being more Visual Studio like.
And I long for some of the features I had back then.

Now don't get me wrong I am all for the new possibilities the new IDE and editor gives a developer, but I wish that not all of the nice features we had in the old IDE had been removed in the new one.

Keeping in mind that I will be sounding some of my customers, when they get a brand new AX installation: "That was possible in our old system!". ;0)

Inspired by http://www.annoyances.org/ I decided to blog a little about the annoyances I have found working with Dynamics AX 2012's new IDE.

So the annoyances I have encountered until now are:

No "New form from template" in code projects

The new feature that I expect is there to help us developers produce more uniform forms (no I am not stuttering), called "New form from template" is quite nice. But why is it that you can only call it directly from the AOT-tree ?

When doing a customization to AX I normally start by creating a code project, so I can put the customized elements in one place for tracking reasons. In the code project, you can create groups, that helps you categorize the customized elements like a group form forms and a group for tables etc.
I normally do this too, because I like things to be tidy.

But when trying to use "New form from template" directly from my Form group node in my code project I am annoyed to see, that this feature is missing. So I have to go back to the AOT to create my form using a template, and afterwards drag it back to my code project.

No drag’n’drop of element-names from AOT into code

Sometimes you need to write an init-method which uses a lot of fields from a table.
In the old IDE, you could open a new window, open the datadictionary and the open the fields node in the table you were working with, highlight the fields you wished to use in your code, and drag it to the editor window.
This is unfortunately not possible any more. Not even for type names, class names.

Intellisense

Maybe it's just me and my habits but I actually miss the function keys from the old IDE, which could give you a list of say tables, or EDT's directly in the editor-window where you could quickly find what you needed.

Now you actually have to know what the element you are looking for is called and start typing that and so Intellisense will help you. I like Intellisense, but I would just looove a combination of the two.

CTRL+O on tables - just not system tables

It's great that you can open a table browser on a table using CTRL+O, quick and easy. Nice.
But why is it not possible to do the same on system tables ?


These were four little things that often annoys me in the Dynamics AX 2012 IDE.

UPDATE - regarding Intellisense.

I actually have an example where the old school ways of drag'n'drop of element from the AOT to the editor, og the shortcut key showing the tablenames and their fields would come in very handy, because of the short comings of Intellisense in the AX IDE.

If you write an update_recordset command in you code then Intellisense is not able to help your determine which field you want to use in the setting-clause.

In the example shown below I need to be able to see what field in the cstLedgerAllocationReference table that I want to be update, but Intellisense is not very helpful. (The field in this example is called AllocationJournalTransRefRecid). So I have to open another AOT, go to the datadictionary / Tables, find the right table, expand the fields nodes to see what the field is called, which is more time consuming - and annoying - than just pressing F2 or having the Intellisense function properly.

mandag den 26. marts 2012

Mental note to self:
In Dynamics AX releases prior to 2012 to get the company currency you could do:

CompanyInfo::find().CurrencyCode;

In 2012 however you would do:

Ledger::findByLegalEntity(CompanyInfo::find().RecId).AccountingCurrency