Wednesday, 30 August 2023

Download a xml file using Dynamics 365 to local folder

Hello All, Today we are using a simple code to download a cml file to local folder using D365fo.I will skip all the steps where you create a xml file , because you can refer to number of blogs posts for this. Here is sample code snippet for downloading xml file to local folder File::SendStringAsFileToUser(XMLDoc, FileName); Thanks, Vivek Chirumamilla

Tuesday, 15 August 2023

Table Modified field using coc in D365fo

/// /// Extension of LedgerJournalTable /// [ExtensionOf(tableStr(LedgerJournalTable))] final class SCA_FS_LedgerJournalTable_Extension { /// /// Proccess the modified field events for LedgerJounal trans /// /// reference to fieldId public void modifiedField(FieldId _fieldId) { next modifiedField(_fieldId); if (_fieldId == fieldNum(LedgerJournalTable, testfield) && this.JournalType == LedgerJournalType::Payment) { //if(this.WorkflowApprovalStatus == LedgerJournalWFApprovalStatus::Approved || this.WorkflowApprovalStatus == LedgerJournalWFApprovalStatus::Rejected) { WorkflowTrackingTable workflowTrackingTable; WorkflowTrackingStatusTable workflowTrackingStatusTable; select firstonly RecId from workflowTrackingStatusTable order by workflowTrackingStatusTable.CreatedDateTime desc where workflowTrackingStatusTable.ContextRecId == this.RecId join User from workflowTrackingTable where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId && workflowTrackingTable.TrackingType == WorkflowTrackingType::Submission; this.ReportedAsReadyBy = workflowTrackingTable.User; //if(this.WorkflowApprovalStatus == LedgerJournalWFApprovalStatus::Approved) { select firstonly RecId from workflowTrackingStatusTable order by workflowTrackingStatusTable.CreatedDateTime desc where workflowTrackingStatusTable.ContextRecId == this.RecId join User from workflowTrackingTable where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId && workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval; this.Approver = HcmWorker::userId2Worker(workflowTrackingTable.User); } if(this.WorkflowApprovalStatus == LedgerJournalWFApprovalStatus::Rejected) { select firstonly RecId from workflowTrackingStatusTable order by workflowTrackingStatusTable.CreatedDateTime desc where workflowTrackingStatusTable.ContextRecId == this.RecId join User from workflowTrackingTable where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId && workflowTrackingTable.TrackingType == WorkflowTrackingType::Rejection; this.RejectedBy = workflowTrackingTable.User; } } } } }

Form Event Handler in D365fo

/// /// Event Hnadler Class For Ledger Journal Table Form /// final class SCA_FS_LedgerJournalTableFormEventHandler { /// /// Approve Event For Approve /// /// sender of event /// Event Args /// [FormControlEventHandler(formControlStr(LedgerJournalTable, Approve), FormControlEventType::Clicked)] public static void Approve_OnClicked(FormControl sender, FormControlEventArgs e) { LedgerJournalTable journal = sender.formRun().dataSource('LedgerJournalTable').cursor(); WorkflowTrackingTable workflowTrackingTable; WorkflowTrackingStatusTable workflowTrackingStatusTable; select firstonly RecId from workflowTrackingStatusTable order by workflowTrackingStatusTable.CreatedDateTime desc where workflowTrackingStatusTable.ContextRecId == journal.RecId join User from workflowTrackingTable where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId && workflowTrackingTable.TrackingType == WorkflowTrackingType::Submission; journal.ReportedAsReadyBy = workflowTrackingTable.User; } /// /// Reject Event For Reject /// /// sender of event /// Event Args /// [FormControlEventHandler(formControlStr(LedgerJournalTable, Reject), FormControlEventType::Clicked)] public static void Reject_OnClicked(FormControl sender, FormControlEventArgs e) { LedgerJournalTable journal = sender.formRun().dataSource('LedgerJournalTable').cursor(); WorkflowTrackingTable workflowTrackingTable; WorkflowTrackingStatusTable workflowTrackingStatusTable; select firstonly RecId from workflowTrackingStatusTable order by workflowTrackingStatusTable.CreatedDateTime desc where workflowTrackingStatusTable.ContextRecId == journal.RecId join User from workflowTrackingTable where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId && workflowTrackingTable.TrackingType == WorkflowTrackingType::Submission; journal.ReportedAsReadyBy = workflowTrackingTable.User; } }

Wednesday, 7 June 2017

GST Tax Caluclation code for Ax 2009 /2012 and AX 7

Hi Friends,

You might be thinking of new code for Tax calculation for GST in INDIA. Here is the sample code snippet for printing Tax info on Reports and Forms.


ITaxableDocument taxableDocument;
ITaxDocument taxDocumentObject;
ITaxDocumentMeasurevalue totalTaxMeasureValue;
ITaxDocumentComponentLineEnumerator componentme;
ITaxDocumentComponentLine componentLine;
ITaxDocumentMeasureEnumerator measureenum;
ITaxDocumentComponentLineMetaData meta;
ITaxDocumentLineEnumerator sublines,sublines1;
ITaxDocumentLine line,line1;
Amount gstTotal ;
;


taxableDocument = TaxableDocumentObject::construct(TaxableDocumentDescriptorFactory::getTaxableDocumentDescriptor(PurchTable::find(526987556)));

taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);

if (taxDocumentObject)
{
totalTaxMeasureValue = taxDocumentObject.getTotalTax();

gstTotal = totalTaxMeasureValue.amountTransactionCurrency();

sublines = taxDocumentObject.subLines();

while(sublines.moveNext())
{
line = sublines.current();

sublines1 = line.lines();
while(sublines1.moveNext())
{

line1 = sublines1.current();

componentme =line1.componentLines();
while(componentme.moveNext())
{

componentLine= componentme.current();

meta = componentLine.metaData();
info(meta.taxComponent());
info(strfmt("%1",componentLine.getMeasure("Base Amount").value().value()));
info(strfmt("%1",componentLine.getMeasure("Rate").value().value()));



}

}
}
}





Vivek Chirumamilla

Tuesday, 12 January 2016

How to Restore the Database with code

Hi Guys,

This is the following command to restore the Database with given .bak file.

DECLARE @fileList TABLE (backupFile NVARCHAR(255))
DECLARE @lastFullBackup NVARCHAR(500)
DECLARE @cadpath NVARCHAR(500)

INSERT INTO @fileList(backupFile)
EXEC xp_cmdshell 'dir C:\AX-Databases\*.bak'


select @lastFullBackup = substring(MAX(backupFile),CHARINDEX('H', MAX(backupFile)),8000) from @fileList
WHERE backupFile LIKE '%.bak'
AND backupFile LIKE '%'+'test' + '%'

set @cadpath = 'C:\AX-Databases\' + @lastFullBackup
RESTORE DATABASE test_Live FROM DISK = @cadpath



Vivek Chirumamilla

Tuesday, 10 March 2015

SQl Query for Financial Dimensions in Ax 2012

Hi Friends,

SQL Query for financial dimensions are often a common requirement we face.

The problem with dimensions is that there are multiple rows of a single default dimensions. Below is the query which returns a single coluumn for the Dimension

stuff((select '-'+[Displayvalue] from DIMENSIONATTRIBUTEVALUESETITEM
inner join DIMENSIONATTRIBUTEVALUESET on DIMENSIONATTRIBUTEVALUESETITEM.DIMENSIONATTRIBUTEVALUESET = DIMENSIONATTRIBUTEVALUESET.RECID where DIMENSIONATTRIBUTEVALUESET.RECID = SQT.DEFAULTDIMENSION FOR XML Path('')),1,1,'') AS DimDESCRIPTION


Now another point is that we often need to select one dimensions out of list of dimensions given here is the solution for it

( select [Displayvalue] from DIMENSIONATTRIBUTEVALUESETITEM
inner join DimensionAttributeValue on DIMENSIONATTRIBUTEVALUESETITEM.DIMENSIONATTRIBUTEVALUE = DimensionAttributeValue.RECID
inner join DIMENSIONATTRIBUTE on DimensionAttributeValue.DIMENSIONATTRIBUTE = DIMENSIONATTRIBUTE.RECID AND DIMENSIONATTRIBUTE.NAME = 'CostCenter'
inner join DIMENSIONATTRIBUTEVALUESET on DIMENSIONATTRIBUTEVALUESETITEM.DIMENSIONATTRIBUTEVALUESET = DIMENSIONATTRIBUTEVALUESET.RECID
where DIMENSIONATTRIBUTEVALUESET.RECID = SQT.DEFAULTDIMENSION ) AS DimDESCRIPTION

We can pass values to Financial Dimensions and get the required output.

Now a simple SQL Query is shown below

SELECT CASE WHEN SALESQUOTATIONTABLE.QUOTATIONSTATUS = 0 THEN 'Created' WHEN SALESQUOTATIONTABLE.QUOTATIONSTATUS = 1 THEN 'Created' WHEN SALESQUOTATIONTABLE.QUOTATIONSTATUS = 2 THEN
'Confirmed' WHEN SALESQUOTATIONTABLE.QUOTATIONSTATUS = 3 THEN 'Created' WHEN SALESQUOTATIONTABLE.QUOTATIONSTATUS = 4 THEN 'Created' END AS 'STATUS',
CASE WHEN SALESQUOTATIONTABLE.QUOTATIONSTATUS = 0 THEN 'Created' WHEN SALESQUOTATIONTABLE.QUOTATIONSTATUS = 1 THEN 'Sent' WHEN SALESQUOTATIONTABLE.QUOTATIONSTATUS = 2 THEN
'Confirmed' WHEN SALESQUOTATIONTABLE.QUOTATIONSTATUS = 3 THEN 'Lost' WHEN SALESQUOTATIONTABLE.QUOTATIONSTATUS = 4 THEN 'Cancelled' END AS 'SubSTATUS',
month(SALESQUOTATIONTABLE.CREATEDDATETIME) AS 'Month', year(SALESQUOTATIONTABLE.CREATEDDATETIME) AS Expr1, SALESQUOTATIONTABLE.CURRENCYCODE,
SUM(SALESQUOTATIONLINE.LINEAMOUNT) AS 'Amount in Currency',
case when SALESQUOTATIONTABLE.CURRENCYCODE = 'AED' then SUM(SALESQUOTATIONLINE.LINEAMOUNT)
when SALESQUOTATIONTABLE.CURRENCYCODE <> 'AED' then SUM(SALESQUOTATIONLINE.LINEAMOUNT) *
((SELECT TOP (1) EXCHANGERATE.EXCHANGERATE/100
FROM EXCHANGERATE INNER JOIN
EXCHANGERATECURRENCYPAIR AS ERCP ON ERCP.RECID = EXCHANGERATE.EXCHANGERATECURRENCYPAIR
WHERE (EXCHANGERATE.VALIDFROM =

(SELECT MAX(EXCHRATES_5.VALIDFROM) AS fromdate
FROM EXCHANGERATE AS EXCHRATES_5 INNER JOIN
EXCHANGERATECURRENCYPAIR ON EXCHANGERATECURRENCYPAIR.RECID = EXCHRATES_5.EXCHANGERATECURRENCYPAIR
WHERE (EXCHANGERATECURRENCYPAIR.FROMCURRENCYCODE = 'AED')AND (EXCHANGERATECURRENCYPAIR.TOCURRENCYCODE = SALESQUOTATIONTABLE.CURRENCYCODE)
) )))
end AS 'Amount in Local Currency',

case when SALESQUOTATIONTABLE.CURRENCYCODE = 'USD' then SUM(SALESQUOTATIONLINE.LINEAMOUNT)
when SALESQUOTATIONTABLE.CURRENCYCODE <> 'USD' then (SUM(SALESQUOTATIONLINE.LINEAMOUNT) *
((SELECT TOP (1) EXCHANGERATE.EXCHANGERATE/100
FROM EXCHANGERATE INNER JOIN
EXCHANGERATECURRENCYPAIR AS ERCP ON ERCP.RECID = EXCHANGERATE.EXCHANGERATECURRENCYPAIR
WHERE (EXCHANGERATE.VALIDFROM =

(SELECT MAX(EXCHRATES_5.VALIDFROM) AS fromdate
FROM EXCHANGERATE AS EXCHRATES_5 INNER JOIN
EXCHANGERATECURRENCYPAIR ON EXCHANGERATECURRENCYPAIR.RECID = EXCHRATES_5.EXCHANGERATECURRENCYPAIR
WHERE (EXCHANGERATECURRENCYPAIR.FROMCURRENCYCODE = 'USD')AND (EXCHANGERATECURRENCYPAIR.TOCURRENCYCODE = SALESQUOTATIONTABLE.CURRENCYCODE)
) )))) end AS 'Amount in USD',



SALESQUOTATIONTABLE.DEFAULTDIMENSION,

( select [Displayvalue] from DIMENSIONATTRIBUTEVALUESETITEM --where DIMENSIONATTRIBUTEVALUESETITEM.DIMENSIONATTRIBUTEVALUE = DIMENSIONATTRIBUTEVALUE.RECID
inner join DimensionAttributeValue on DIMENSIONATTRIBUTEVALUESETITEM.DIMENSIONATTRIBUTEVALUE = DimensionAttributeValue.RECID
inner join DIMENSIONATTRIBUTE on DimensionAttributeValue.DIMENSIONATTRIBUTE = DIMENSIONATTRIBUTE.RECID AND DIMENSIONATTRIBUTE.NAME = 'LineOfBusiness'
inner join DIMENSIONATTRIBUTEVALUESET on DIMENSIONATTRIBUTEVALUESETITEM.DIMENSIONATTRIBUTEVALUESET = DIMENSIONATTRIBUTEVALUESET.RECID
where DIMENSIONATTRIBUTEVALUESET.RECID = SALESQUOTATIONTABLE.DEFAULTDIMENSION ) AS DimDESCRIPTION
FROM SALESQUOTATIONTABLE LEFT OUTER JOIN
SALESQUOTATIONLINE ON SALESQUOTATIONTABLE.QUOTATIONID = SALESQUOTATIONLINE.QUOTATIONID
WHERE /* (SALESQUOTATIONTABLE.CREATEDDATETIME BETWEEN @fromDate AND @toDate) AND *//*month(SALESQUOTATIONTABLE.CREATEDDATETIME) > 1 and */(SALESQUOTATIONTABLE.DATAAREAID = 'dat') AND (SALESQUOTATIONTABLE.QUOTATIONSTATUS <> 2) AND
(SALESQUOTATIONLINE.DATAAREAID = 'dat')
GROUP BY SALESQUOTATIONTABLE.QUOTATIONSTATUS, year(SALESQUOTATIONTABLE.CREATEDDATETIME),month(SALESQUOTATIONTABLE.CREATEDDATETIME), SALESQUOTATIONTABLE.CURRENCYCODE,
SALESQUOTATIONTABLE.DEFAULTDIMENSION

UNION
SELECT 'Confirmed' AS 'STATUS', 'Confirmed' AS 'SubSTATUS', month(SQT.CONFIRMDATE) AS 'Month',year(SQT.CONFIRMDATE) AS 'Year', SQT.CURRENCYCODE,
SUM(SQNL.LINEAMOUNT) AS 'Amount in Currency',
case when SQT.CURRENCYCODE = 'AED' then SUM(SQNL.LINEAMOUNT)
when SQT.CURRENCYCODE <> 'AED' then SUM(SQNL.LINEAMOUNT) *
((SELECT TOP (1) EXCHANGERATE.EXCHANGERATE/100
FROM EXCHANGERATE INNER JOIN
EXCHANGERATECURRENCYPAIR AS ERCP ON ERCP.RECID = EXCHANGERATE.EXCHANGERATECURRENCYPAIR
WHERE (EXCHANGERATE.VALIDFROM =

(SELECT MAX(EXCHRATES_5.VALIDFROM) AS fromdate
FROM EXCHANGERATE AS EXCHRATES_5 INNER JOIN
EXCHANGERATECURRENCYPAIR ON EXCHANGERATECURRENCYPAIR.RECID = EXCHRATES_5.EXCHANGERATECURRENCYPAIR
WHERE (EXCHANGERATECURRENCYPAIR.FROMCURRENCYCODE = 'AED')AND (EXCHANGERATECURRENCYPAIR.TOCURRENCYCODE = SQT.CURRENCYCODE)
) )))
end AS 'Amount in Local Currency',

case when SQT.CURRENCYCODE = 'USD' then SUM(SQNL.LINEAMOUNT)
when SQT.CURRENCYCODE <> 'USD' then (SUM(SQNL.LINEAMOUNT) *
((SELECT TOP (1) EXCHANGERATE.EXCHANGERATE/100
FROM EXCHANGERATE INNER JOIN
EXCHANGERATECURRENCYPAIR AS ERCP ON ERCP.RECID = EXCHANGERATE.EXCHANGERATECURRENCYPAIR
WHERE (EXCHANGERATE.VALIDFROM =

(SELECT MAX(EXCHRATES_5.VALIDFROM) AS fromdate
FROM EXCHANGERATE AS EXCHRATES_5 INNER JOIN
EXCHANGERATECURRENCYPAIR ON EXCHANGERATECURRENCYPAIR.RECID = EXCHRATES_5.EXCHANGERATECURRENCYPAIR
WHERE (EXCHANGERATECURRENCYPAIR.FROMCURRENCYCODE = 'USD')AND (EXCHANGERATECURRENCYPAIR.TOCURRENCYCODE = SQT.CURRENCYCODE)
) )))) end AS 'Amount in USD',


SQT.DEFAULTDIMENSION,
( select [Displayvalue] from DIMENSIONATTRIBUTEVALUESETITEM --where DIMENSIONATTRIBUTEVALUESETITEM.DIMENSIONATTRIBUTEVALUE = DIMENSIONATTRIBUTEVALUE.RECID
inner join DimensionAttributeValue on DIMENSIONATTRIBUTEVALUESETITEM.DIMENSIONATTRIBUTEVALUE = DimensionAttributeValue.RECID
inner join DIMENSIONATTRIBUTE on DimensionAttributeValue.DIMENSIONATTRIBUTE = DIMENSIONATTRIBUTE.RECID AND DIMENSIONATTRIBUTE.NAME = 'LineOfBusiness'
inner join DIMENSIONATTRIBUTEVALUESET on DIMENSIONATTRIBUTEVALUESETITEM.DIMENSIONATTRIBUTEVALUESET = DIMENSIONATTRIBUTEVALUESET.RECID
where DIMENSIONATTRIBUTEVALUESET.RECID = SQT.DEFAULTDIMENSION ) AS DimDESCRIPTION
FROM SALESQUOTATIONTABLE AS SQT LEFT OUTER JOIN
SALESQUOTATIONLINE AS SQNL ON SQT.QUOTATIONID = SQNL.QUOTATIONID
WHERE /*(SQT.CONFIRMDATE BETWEEN @fromDate AND @toDate) AND*/(SQT.DATAAREAID = 'dat') AND (SQT.QUOTATIONSTATUS = 2) AND (SQNL.DATAAREAID = 'dat')
GROUP BY SQT.QUOTATIONSTATUS, month(SQT.CONFIRMDATE),year(SQT.CONFIRMDATE), SQT.CURRENCYCODE, SQT.DEFAULTDIMENSION



Vivek Chirumamilla

Wednesday, 17 December 2014

SSRS Report values of Company Heading , Page Numbers, Date And Time Printing and Row Numbers

Hi Friends,

Today we will use simple ways to print on the textbox

Company Information
=Microsoft.Dynamics.Framework.Reports.DataMethodUtility.PostDataMethodEvaluation(Microsoft.Dynamics.Framework.Reports.DataMethodUtility.
UpdateAxContextPartition(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value, Parameters!AX_RenderingCulture.Value, Parameters!AX_PartitionKey.Value),Microsoft.Dynamics.Framework.Reports.DataMethodUtility.GetFullCompanyNameForUser(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value))

Page Numbers On the Header Section

=System.String.Format(Labels!@SYS182566, "" & Globals!PageNumber & "", "" & Globals!TotalPages & "")

Date And Time Printing on the Header Section

=Microsoft.Dynamics.Framework.Reports.DataMethodUtility.PostDataMethodEvaluation(Microsoft.Dynamics.Framework.Reports.DataMethodUtility.UpdateAxContextPartition(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value, Parameters!AX_RenderingCulture.Value, Parameters!AX_PartitionKey.Value),Microsoft.Dynamics.Framework.Reports.DataMethodUtility.ConvertUtcToAxUserTimeZoneForUser(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value, System.DateTime.UtcNow, "d", Parameters!AX_RenderingCulture.Value)) & vbCrLf & Microsoft.Dynamics.Framework.Reports.DataMethodUtility.PostDataMethodEvaluation(Microsoft.Dynamics.Framework.Reports.DataMethodUtility.UpdateAxContextPartition(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value, Parameters!AX_RenderingCulture.Value, Parameters!AX_PartitionKey.Value),Microsoft.Dynamics.Framework.Reports.DataMethodUtility.ConvertUtcToAxUserTimeZoneForUser(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value, System.DateTime.UtcNow, "t", Parameters!AX_RenderingCulture.Value))

To Print the row numbers in the Grid

=RowNumber(Nothing)

Vivek Chirumamilla

Monday, 15 December 2014

C# code to use in Ax for fetching records

Hi Friends,

Here is the C# sharp code to login and retreive records in Ax

using System;
using System.Data;
using System.Security.Permissions;
using Microsoft.Dynamics.Framework.Reports;
using System.Data.SqlClient;

public partial class test
{

[DataMethod(), PermissionSet(SecurityAction.Assert, Name = "FullTrust")]
public static System.Data.DataTable DataMethod1()
{

System.Data.DataTable customers2 = new DataTable();
string queryString = "SELECT * FROM dbo.CustTable";

SqlConnection connection = new SqlConnection();
connection.ConnectionString =
"Data Source=@server;" +
"Initial Catalog=@DB;" +
"Integrated Security=SSPI;";

SqlCommand cmd = new SqlCommand(queryString, connection);

connection.Open();
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());

return dt;


}

}




Vivek Chirumamilla

Tuesday, 25 November 2014

Financial Dimension values in Ax 2012


Hi Friends ,

In Ax Financial Dimensions are widely used. In Ax 2012 these dimensions are not at all individual fields, all these Financial dimensions are combined into a single field Default Dimension. This default dimension carry reference to a set of Financial dimension.

The question is how do we get single value of the dimension or all the set of values using this financial dimensions. Here is the sample code which gives the values of financial dimensions.

public static SysDim DefaultDimensionValue(DimensionDefault _dimensionDefault, Description _nameofDimension)
{

DimensionAttributeValueSetStorage dimensionStorage;
Counter i;
SysDim nameofDimension;


// Get dimension storage
if (_dimensionDefault)
{
dimensionStorage = DimensionAttributeValueSetStorage::find(_dimensionDefault);

for (i=1 ; i<= dimensionStorage.elements() ; i++)
{
if (DimensionAttribute::find(dimensionStorage.getAttributeByIndex(i)).Name == _nameofDimension)
{
nameofDimension= dimensionStorage.getDisplayValueByIndex(i);
break;
}
else
{
nameofDimension= '';
}
}
}

return nameofDimension;
}

The above sample code gives values dimension value if you have default dimesion and name of Dimension. If you want all the values just tweak this code a little bit.

Vivek Chirumamilla

Wednesday, 29 October 2014

How to get the last Activated Form

Hi Friends

Check this

formRun = infolog.parmLastActivatedForm().object();
tableReference = formRun.docCursor().TableId;

Vivek Chirumamilla

Tuesday, 28 October 2014

Address System in Ax 2012 R3

Hi Friends,

Ax 2012 has a complex Address when compared to the previous versions of Ax.

In this address is not directly linked to the Customer or Vendor directly.

Customer or Vendor has Party which is linked to the DirParty.

DirParty Contains the Primary postal address reference to Logistics Location RecId which is reflected in LogisticsPostalAddress.

In short Dirparty contains the value of Location for searching address in LogisticsPostalAddress.

Vivek Chirumamilla

Thursday, 4 July 2013

Record Link List in Ax 2012


Hi Friends,

We have RecordLinkList which is used to store buffers of different tables in one go.

Here below is the example of how to use Record Lint List.



RecordLinkList recordLinkList;
;
recordLinkList = new RecordLinkList();

for (buffer = McsEmValConsumptionValidationView_DS.getFirst(true) ? McsEmValConsumptionValidationView_DS.getFirst(true) : McsEmValConsumptionValidationView_DS.cursor(); buffer; buffer = McsEmValConsumptionValidationView_DS.getnext())
{
if (buffer.CalculatedConsumptionValidUntilDate == FcsDateTimeAPI::DateNull())
{
recordLinkList.ins(buffer);
}
}

while retrieving you can use this

hasNext = recordLinkList.first();
while (hasNext)
{
common = recordLinkList.peek();
switch (common.TableId)
{
case tableNum(McsEmValConsumptionValidationView):
consValView = common;
calculatedConsumption = McsEmCalcCalculatedConsumption::find(consValView.CalculatedConsumptionId);
break;

case tableNum(McsEmValProcessErrorDetailInfo):
processErrorDetailInfo = common;
calculatedConsumption = McsEmCalcCalculatedConsumption::find(processErrorDetailInfo.CalculatedConsumptionId);
break;

default:
hasNext = recordLinkList.next();
continue;
}

Vivek Chirumamilla

Wednesday, 5 June 2013

How to restrict combo Box Controls in Ax 2012

Hi Friends ,


Today we are going to see how to restrict combo Box Controls in Ax 2012

public FormComboboxControl removeInactiveInvoiceTypes(FormComboboxControl _formComboboxControl)
{
FormComboboxControl formComboboxControl;
DictEnum dictEnum;

MInvoiceTypeTable invoiceTypeTable ;
;

formComboboxControl = _formComboboxControl;

dictEnum = new DictEnum(enumNum(BilInvoiceTypes));

numberOfInvoiceTypes = dictEnum.values() - 1;

while select InvoiceType from invoiceTypeTable
where invoiceTypeTable.UseForFreeTextInvoice == noYes::No
{
formComboboxControl.delete(dictEnum.value2Label(invoiceTypeTable.InvoiceType));

numberOfInvoiceTypes--;
}

return formComboboxControl;
}

In the run Method element.removeInactiveInvoiceTypes(InvoiceType);


Vivek Chirumamilla

Sunday, 7 April 2013

Query Dialog Fields Lookup in Classes in Ax 2012


Hi Friends,

Today we are going to do the query Lookup in dialog of classes because most of the clients would ask for this type of requirement.

Now we would place a customer Id lookup in the dialog. Declare QueryRun and Customer Id.
public void initParmDefault()
{
Query query;
;
super();
query = new Query();
query.addDataSource(tableNum(CustTable));
queryRun = new QueryRun(query);
}

public container pack()
{
;
return [#CurrentVersion, #CurrentList, queryRun.pack()];
}
public boolean unpack(container _packedClass)
{
Version version = runbase::getVersion(_packedClass);
Container packedQuery;
;
switch (version)
{
case #CurrentVersion:
[version, #CurrentList, packedQuery] = _packedClass;

if (packedQuery)
queryRun = new QueryRun(packedQuery);
break;

default:
return false;
}
return true;
}
public QueryRun queryRun()
{
;
return queryRun;
}
boolean showQueryValues()
{
;
return true;
}
By these above modification you can see Customer Id in the Query Dialog box.

Vivek Chirumamilla

Thursday, 28 March 2013

Running the Wizrad through Code in Ax 2012

Hi Friends,

Today we are going to see how we can run the wizard through code.Just by clicking the button the wizard will run. We have a doubt what is the point of running the wizard automatically without providing values. We can also pass the values through code and run the wizard.

Here is a snipet of the existing functionality where a relation wizard is run between customer and connection.The relation wizard is called from a class.

Where we are going the run the wizard without Human Interaction .

Here are the steps below:

Cerate a new class and extend with sysWizard or your wizard which is running.


FormName formName()
{
return formstr(McsRelationWizard);
}

private void createRelation(CustAccount _custAccount , McsConnectionId _connectionId)
{
Form form;
Args argsLocal = new Args();
;
this.initFormRun();

form = formRun.form();
argsLocal.object(form);
argsLocal.caller(this);
formRun = classfactory.formRunClass(argsLocal);
formRun.init();
formRun.QcHandOver(_custAccount,_connectionId);
}
public static void main(CustAccount _custAccount , McsConnectionId _connectionId)
{
QcHandOverRelation wizard = new QcHandOverRelation();

;
wizard.createRelation(_custAccount,_connectionId);
wizard.run();

}



Vivek Chirumamilla

Friday, 22 March 2013

Passing Information from to another based on Selection in Ax 2012


Hi Friends,

In my previous posts I had shown how to open a form in runtime , but opening the form in runtime is one aspect and passing the information to the base form based on user selections is another hurdle.

Today we are going to pass the customer from one form to another.

We have a customer field in a form and this customer has to be searched from another form where the list of customers are shown. User places the cursor on the serach and press use customer this selected customer must be returned to the cutomer field



To return the customer which we have selected , write doen the following code in the clicked method of the use customer.

void clicked()
{
;

element.args().parm(CustTable.AccountNum);

Element.close();

super();
}


While in the first form write the follwing code to open the form for selection and taking the value for the which has been returned.

void clicked()
{
FormRun formRun;
Args args;
AccountNum retValue;
;

args = new Args();
args.name(Formstr(McsCustomerSearch));
args.caller(element);

formRun = classFactory.formRunClass(args);
formRun.Init();

formRun.run();
formRun.wait();

if (args.parm())
{
retValue = args.parm();
CustomerId.text(retValue);
CustomerId.modified();
}
}

By this whatever value we have selected in the second form not only passes to the first form but also the value is diplayed in the current field.

Happy Daxing

Vivek Chirumamilla

Thursday, 22 November 2012

How to open a form in runtime in Ax 2012

Hi Friends,

Today we are going to open a form in runtime in Ax 2012.

There are two ways of opening a form in runtime in Ax 2012.
Below given codes are for just example.

The first type of opening a form is given below

client static Object OpenToolBar()
{
Object toolBarForm = null;
Args args = new Args();
;
args.name(formStr(formName));
toolBarForm = classFactory.formRunClass(args);
toolBarForm.init();
toolBarForm.run();
toolBarForm.detach();
return toolBarForm;
}

The second type is given below

client static Object getToolBarObject()
{
ObjectIdent objIdent = infolog.globalCache().get(formStr(formname),null,null);
Object toolBarForm = objIdent ? objIdent.object() : null;
;
if(!toolBarForm)
{
toolBarForm = S3SecurityToolBarOpen::OpenToolBar();
}
else
toolBarForm.setActive();

return toolBarForm;
}

Vivek Chirumamilla

Tuesday, 20 November 2012

Dict Class in Ax 2012

Hi Friends,

Today we will have a slight introduction to dictclass .

DictClass have wide vaiety of operations one of them is call Object.

We have created a object for PurchFormLetter_Invoiced() and call the method called missingnumber in the class.

The output of the class is printed at the end of section.

static void Job_Example_DictClass_CallObject(Args _args)
{
DictClass dictClass;
anytype retVal;
str resultOutput;
PurchFormLetter_Invoice p = new PurchFormLetter_Invoice();
ExecutePermission perm;

perm = new ExecutePermission();

// Grants permission to execute the DictClass.callObject method.
// DictClass.callObject runs under code access security.
perm.assert();

dictClass = new DictClass(classidget(p));
if (dictClass != null)
{
retVal = dictClass.callObject("missingNumber", p);
resultOutput = strfmt("Return value is %1", retVal);
print resultOutput;
pause;
}

// Closes the code access permission scope.
CodeAccessPermission::revertAssert();
}

Vivek Chirumamilla

Security Policy property in Ax 2012


Hi Friends,

I have been working on the security . I have came across the property of ContextType and ContextString.

I will to explian ContextType and ContextString properties.

In ContextType LookUp there will be three values they are

1.ContextString

2.RoleName

3.RoleProperty.

Here don't get confused with the ContextString in LookUp and ContextString in Properties.

They both are related to each other.

Case 1: When ContextType property is set to "ContextString"

The ContextString property is empty. This combination implies that when it is enabled, this security policy will always be applicable for all users.

Case 2: When ContextType property is set to "RoleName"

The RoleName Property will be enabled and it shows roles select the appropriate Role for the situation.The Role which is activated for the user the security policy applies.

Case 3: When ContextType property is set to "RoleProperty"

The RoleProperty is the combination of ContextString and RoleName. So both the properties will be activated.

I hope you have understood the concept of ContextType property in Security Policy.



Vivek Chirumamilla

Find All Fields that user cannot access in Ax 2012

Hi Friends,

Note:: The program given below is a sample program and it cannot be used in real scenarios in Ax 2012.

Today we will have a small program in Ax 2012 that is used to find out how many tables and how may field in the tables the security keys are attached and find out which keys there will be security for that.

Here is the program which I have been talking about-----

static void GmTrimAccessFieldScan(Args _args)
{
// Edit the following three macro values to your needs. For example:
// ** Start: with a table whose name starts with an 'A'.
// ** Stop: with a table whose name starts with a 'Z'.
#define.SearchTableNameRangeStart("")
#define.SearchTableNameRangeStop("")
#define.TargetTableNameLikeFilter("*")

TreeNode tnTable,
tnField;
str sTableAosAuth,
sFieldAosAuth;
int nCountOfTpfTablesFound = 0,
nCountOfAotTables = 0,
nCountOfTrimmedFields = 0;

// Establish start node among the table nodes.
if (#SearchTableNameRangeStart == "")
{
tnTable = TreeNode::findNode
("\\Data Dictionary\\Tables").AOTfirstChild();
}
else
{
tnTable = TreeNode::findNode
("\\Data Dictionary\\Tables\\" + #SearchTableNameRangeStart);
}


while (true)
{
nCountOfAotTables++;
// Provide ongoing progress reports.
if ((nCountOfAotTables MOD 50) == 3)
{
print int2Str(nCountOfAotTables)
+ " tables examined so far, at " + tnTable.AOTname();
print int2Str(nCountOfTpfTablesFound) + " TPF okay tables found so far.";
print int2Str(nCountOfTrimmedFields) + " trimmed fields found so far.";
print "---------------- Wait...";
}
// Perhaps stop before the end of the AOT, for convenience.
if (#SearchTableNameRangeStop < tnTable.AOTname() &&
#SearchTableNameRangeStop != ""
)
{
break;
}

// Apply the table name wild card filter.
if (tnTable.AOTname() like #TargetTableNameLikeFilter)
{
sTableAosAuth = tnTable.AOTgetProperty('AOSAuthorization');
// Test whether there is authority to access the table, under TPF.
if (sTableAosAuth != 'None')
{
nCountOfTpfTablesFound++;
// Loop through the fields on this table.
for (tnField = TreeNode::findNode
('\\Data Dictionary\\Tables\\'
+ tnTable.AOTname()
+ '\\Fields').AOTfirstChild();
tnField;
tnField = tnField.AOTnextSibling()
)
{
sFieldAosAuth = tnField.AOTgetProperty('AOSAuthorization');
// Test whether there is authority to access the field.
if (sFieldAosAuth != 'No')
{
nCountOfTrimmedFields++;
info(strFmt('%1 %2 is a trimmed field that you cannot access.',
tnTable.AOTname(), tnField.AOTname()));
}
} // for each field in AOT
} // if table is guarded by the Table Protection Framework (TPF).
} // name is Like

// Prepare for next interation of this loop.
tnTable = tnTable.AOTnextSibling();
if (tnTable == null) break;

} // for each table in AOT

print "-------- Final Report (see also the Infolog) --------";
print int2Str(nCountOfAotTables)
+ " tables examined so far, at end.";
print int2Str(nCountOfTpfTablesFound) + " TPF tables found so far, at end.";
print int2Str(nCountOfTrimmedFields) + " trimmed fields found so far, at end.";
print "-------- Done. --------";
pause;
}



Vivek Chirumamilla