RSS

Get all dimension values from Default Dimension

DefaultDimensionView can be used to get dimension values of default dimension.

Default Dimension View

 
 

Encryption / decryption(Cryptography) Using x++

Many times we have sensitive data that we don’t want to display to the users. One example for this case is the budget amount in the forecast budgets for the employees’ end of service. We can encryption and decryption in AX by using .Net provided classes.

Below is the example for the encryption.

public static str encrypt(str _txtToEncrypt, str _password)

{

// convert from string to byte array

ClrObject txtByteArray = System.Text.Encoding::get_ASCII().GetBytes(_txtToEncrypt);

ClrObject encryptor;

ClrObject cryptoStream;

ClrObject encryptedtxt;

System.String stringEncrypted;

ClrObject pdb = new ClrObject(‘System.Security.Cryptography.PasswordDeriveBytes’ , _password, OTH_Cryptography::passwordNasheet());

// create intance of memory stream

System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();

ClrObject streamMode = ClrInterop::parseClrEnum(‘System.Security.Cryptography.CryptoStreamMode’, ‘Write’);

// define the alogorithm you would lime to use,  MD5, DES etch

ClrObject algorithm = System.Security.Cryptography.DES::Create();

// Now set the key and the IV.

algorithm.set_Key(pdb.GetBytes(32));

algorithm.set_IV(pdb.GetBytes(16));

// create intance of CryptoStream

encryptor = algorithm.CreateEncryptor();

cryptoStream = new ClrObject(‘System.Security.Cryptography.CryptoStream’ , memoryStream, encryptor, streamMode);

// Write the data and make it do the encryption

cryptoStream.Write(txtByteArray, 0, txtByteArray.get_Length());

cryptoStream.Close();

encryptedtxt = memoryStream.ToArray();

// convert from byter array to string

stringEncrypted = ClrInterop::staticInvoke(‘System.Convert’, ‘ToBase64String’, encryptedtxt);

return stringEncrypted;

}

public static str decrypt(str _cipherText, str _password)

{

ClrObject cryptoStream;

ClrObject decryptor;

ClrObject decryptedData;

System.String decrryptText;

ClrObject cipherBytes = System.Convert::FromBase64String(_cipherText);

ClrObject pdb = new ClrObject(‘System.Security.Cryptography.PasswordDeriveBytes’ , _password, OTH_Cryptography::passwordNasheet());

System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();

ClrObject streamMode = ClrInterop::parseClrEnum(‘System.Security.Cryptography.CryptoStreamMode’, ‘Write’);

ClrObject algorithm = System.Security.Cryptography.DES::Create();

algorithm.set_Key(pdb.GetBytes(32));

algorithm.set_IV(pdb.GetBytes(16));

decryptor = algorithm.CreateDecryptor();

cryptoStream = new ClrObject(‘System.Security.Cryptography.CryptoStream’ , memoryStream, decryptor, streamMode);

// Write the data and make it do the decryption

cryptoStream.Write(cipherBytes, 0, cipherBytes.get_Length());

cryptoStream.Close();

decryptedData = memoryStream.ToArray();

// Now we need to turn the resulting byte array into a string.

decrryptText =  System.Text.Encoding::get_ASCII().GetString(decryptedData);

return decrryptText;

}

 

Tags: , , , , , , , , , , , ,

Replace financial dimension value in the Budget Ledger dimension(Budget Planning)

In my recent post, Replace financial dimension value in the ledger dimension. we saw how can we replace the financial dimension in the ledger dimension.

In AX 2012 R3,  Budget planning functionality brought budget ledger dimension which is the extension of the ledger dimension.

Today, we will see how can we replace financial dimension in the budget ledger dimension.

AxdDimensionUtil having methods for the budget planning ledger dimension here is the link for that. Budget Planning helper methods in the AxdDimensionUtil

Below is the method can be used to replace dimension value in the budget planning ledger dimension. Just pass the ledger dimension(RecId), DimensionName (which you want to replace ) and new dimension value.

public static LedgerDimensionBudgetPlanning replaceDimValueBudgetPlanning(
LedgerDimensionBudgetPlanning   _ledgerDimension,
Name                            _dimAttrName,
DimensionValue                  _dimValue)
{
LedgerDimensionBudgetPlanning   ledgerDimension;
container                       conLedgerDimension;

conLedgerDimension = AxdDimensionUtil::getBudgetPlanningAccountValue(_ledgerDimension);

if (conFind(conLedgerDimension, _dimAttrName))
{
conLedgerDimension = conpoke(conLedgerDimension, conFind(conLedgerDimension, _dimAttrName)+1, _dimValue);
}
else
{
conLedgerDimension = conpoke(conLedgerDimension, 3, conPeek(conLedgerDimension, 3) +1);
conLedgerDimension = conIns(conLedgerDimension, conlen(conLedgerDimension) +1, _dimAttrName);
conLedgerDimension = conIns(conLedgerDimension, conlen(conLedgerDimension) +1, _dimValue);
}

ledgerDimension = AxdDimensionUtil::getBudgetPlanningAccountId(conLedgerDimension);

return ledgerDimension;
}

 

 

Tags: , , , , , , , ,

Get value from budget planning ledger dimension.

AxdDimensionUtil class is providing helpful methods for handling the budget planning ledger dimension.

To get the ledger dimension from the value (offset string)
AxdDimensionUtil::getBudgetPlanningAccountId(offsetAccountString);
To get more details see To get the ledger dimension from the value
To get the value (offset string from the ledger dimension)
conLedgerDimension = AxdDimensionUtil::getBudgetPlanningAccountValue(
                                                   _ledgerDimension);
This method return the container

//3110101-104190-1305—00000005,Account structure – MRKT,4,
//MainAccount,3110101,Org_CC,104190,Opr_CC,1305,Department,00000063

It gives you the display value, account structure,  number of dimension including main account.

 

Tags: , , , , , ,

Replace financial dimension value in Ledger dimension

Dimension value can be replaced in a default dimension by using  below standard method.

DimensionDefaultingService::serviceReplaceAttributeValue(
target,
_source,
_dimensionAttributeId)

What If we need to replace the dimension value of a ledger dimension. Below method can be used to replace  the dimension value in a ledger dimension.

public server static LedgerDimensionAccount replaceDimensionValue(
LedgerDimensionAccount _ledgerDimension,
DimensionAttribute     _dimAttr,
DimensionValue         _toDimensionVal)
{
LedgerDimensionAccount              ledgerDimension;
DimensionDefault                    defaultDimension;
DimensionDefault                    replaceDimension;
DimensionAttributeValue             dimAttrValue;
DimensionAttributeValueSetStorage   dimAttrValDimStorage;

if (_toDimensionVal != ”)
{
// convert to Default dimensions
defaultDimension =       DimensionStorage::getDefaultDimensionFromLedgerDimension(_ledgerDimension);
dimAttrValDimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);

dimAttrValue = DimensionAttributeValue::findByDimensionAttributeAndValue(_dimAttr, _toDimensionVal);

// add dimension value to Default dimension
dimAttrValDimStorage.addItemValues(_dimAttr.RecId, dimAttrValue.RecId, dimAttrValue.HashKey);
replaceDimension = dimAttrValDimStorage.save();

ledgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(_ledgerDimension, replaceDimension);
}

else

{

ledgerDimension = _ledgerDimension;

}

return ledgerDimension;
}

 
 

Tags: , , , , , , , , ,

How to make http request with X++

Below code shows how can we make http request with x++. We are using .Net classes to send the request.

System.Net.WebRequest       Request;
System.Net.WebResponse      Response;
System.IO.Stream            RequestStream;
System.IO.Stream            ResponseStream;
System.IO.StreamReader      readStream;
System.IO.StreamWriter      writer;
str                         strResponse;
str                         postAddress;
;

postAddress = #AXToServicePath + messageType;
Request = System.Net.WebRequest::Create(postAddress);
Request.set_Method(#postMethod);
Request.set_ContentType(#contentType);
Request.set_Timeout(#ServiceTimout);

// Wrap the request stream with a text-based writer
writer = new  System.IO.StreamWriter(Request.GetRequestStream());
// Write the XML text into the stream
writer.WriteLine(message);
writer.Close();
// Send the data to the webserver

Response = Request.GetResponse();
ResponseStream = Response.GetResponseStream();

readStream = new System.IO.StreamReader(ResponseStream);
strResponse = readStream.ReadToEnd();

 

Tags: , , , , , ,

Override change management settings in Purchase Order

Change management introduces a managed workflow that makes sure that purchase orders are locked when they have been approved.

https://technet.microsoft.com/en-us/library/hh802989.aspx

Some time we need to give exception for some vendors so, AX provides us way to override the change management settings per vendor per Purchase order level. For details , Please see the below the link.

http://dynamicsteaching.com/importance-of-change-management-feature-in-ax-2012/

 

 
Leave a comment

Posted by on April 20, 2016 in AX 2012, AX Knowledge Base

 

Tags: , ,

Dynamics AX 2012 R3 with Team Foundation Server online

DAX developer can connect AX 2012 with online TFS. It is free for up to five users.

It’s very easy to setup AX 2012 R3 with TFS Online and very well defined in the below link. 

Setup AX 2012 R3 Source Control with TFS online

Your client that is having VS 2010 may face issue because you also need hotfix

KB 2662296.

 

 

 

 

 

 

 
Leave a comment

Posted by on February 8, 2016 in AX 2012, Team Foundation Server, x++ coding

 

Tags: , ,

Patterns used in the Migration for MorphX Report to SSRS Report

Old pattern/usage New programming model pattern
RDP report with:1.       Simple Grouping

2.       Validation

–          Create RDP contract.-          Implement SysOperationValidatable and implement validation.

–          Do grouping on contract.

 

Example:

–          AssetDepreciationLedger_IT

–          InventABC

RDP report with complex grouping e.g. horizontal, vertical, nesting etc. OR multiple groups etc. –          Do grouping in VS. Provides you modeling capabilities.
Query/DataMethod/OLAP report with group –          Do grouping in VS.
–          Custom fields created in dialog i.e. field is not a report parameter-          Field added based on certain condition.

–          Custom dialog fields are added and report parameter populated based on that.

–          Create UI Builder:-          Move code in “addCustomCtrl” to UIBuilder.build().

–          Move “getFromDialog”  to UIBUilder.getFromDialog() and populate contract.

–          Associate UI builder class with contract by using attribute “SysOperationContractProcessingAttribute(classstr(UIBuilderName), SysOperationDataContractProcessingMode::CreateUIBuilderForRootContractOnly)”

–          Optional: Create controller, if further modification of contract needs to be done before running. Do it in preRunModifyContract().

Example:

–          AgreementFollowup

–          BOMPartOf

–          Code needs to react to dialog field events. E.g. field modified etc. –          Create UI Builder:-          In postRun(), register override methods for field events and associate with methods.

Example:

–          BudgetFundsAvailableUIBuilder

BudgetDetailsUIBuilder

–          Dialog field needs to be changed to have different button type than default-          Field needs to turn on flag on grouping. –          Create UI Builder:-          In postBuild(), get the dialog field from binding info and change.

Example

–          BudgetDetailsUIBuilder

–          Helper class turns on/off visibility of report parameter, so new custom parameters can be added. –          Change the report parameter in report design to hidden. Framework will take care of not showing it on AX form.
–          Helper class add caption for the report. –          This should be avoided. The framework will use the label on the menu item launching the report as caption. So please change the label on menu item.-          The above will cover most reporting scenario.

–          For case where same report is used in multiple reports, then override controller.prePromptModifyContract() and set this. parmDialogCaption().

 

Example

–          AgreementFollowUpController

–          Enable/Disable a dialog field based on certain condition –          Create UI builder:-          Override getFromDialog() if you want to get custom field value from dialog.

–          Override postBuild(), to enable/disable fields.

Example:

–          CustAccountStatementInt

 

–          Query is modified based on caller args BEFORE UI is rendered. –          Create controller:Override prePromptModifyContract().

 

Example

–          AgreementFollowUpController

–          Query is modified BEFORE report is run. –          Create controller:Override preRunModifyContract()
–          Report name is changed based on caller args or UI parameter –          Create controller:Override preRunModifyContract()

 

Example:

–          AgreementFollowUpController

–          Helper class uses Print management –          Create controller:Override run() (refer to sample report)

Override preRunModifyContract(), prePromptModifyContract() as needed.

 

Example:

–          CustInterestNoteHelper

–          Report parameter UI should NOT show. –          Create controller:In main(), before controller.startOperation(), call controller.parmShowDialog(false)
–          Report uses temp table from caller –          Create controller-          Get temp table from caller, and use SRSTmpTblMarshaller class to save the data

–          Develop RDP class to extract this data and do biz logic processing

 

Example:

–          Cheque_US

 

 

 

Tags: , , , , , , , , ,