Showing posts with label vivek. Show all posts
Showing posts with label vivek. Show all posts

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

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

Friday, 26 October 2012

Date Conversion to string in Ax 2012

Hi Friends,

Today we will have a look at the date values and its conversion to string values in Ax 2012.

For Eg: We have a variable called Date d

We have assigned a value to it d = 20/07/1988



str Date2StrEasyLocal(date _date)
{
return ( date2Str
(_date,
321, // YMD
DateDay::Digits2,
DateSeparator::Hyphen,
DateMonth::Digits2,
DateSeparator::Hyphen,
DateYear::Digits4) );
}


str s = Date2StrEasyLocal(d);

By the above way we can covert the dates in string values.

Vivek Chirumamilla

Tuesday, 2 October 2012

Other Databse Connection using Ax 2009

hi friends,

Connection with other database can be established from Ax.

This database may not have connection with the database you are using.

By using ODBCConnetion(Other DataBase Connection) you can use it.

I have given a sample code and example of it.

static void dbODBCConnection(Args _args)
{
LoginProperty loginProp;
ODBCConnection conn;
Resultset resultSet, resultSetCount;
Statement statement1, statement2;
;

loginProp = new LoginProperty();
loginProp.setServer('172.16.0.999');
loginProp.setDatabase('AxDynamics2009RND');


conn = new ODBCConnection(loginProp);

statement1 = conn.createStatement();
resultSet = statement1.executeQuery("SELECT * from Attandance");

while (resultSet.next())
{
info(resultSet.getString(2));
}
}


happy daxing,

Vivek Chirumamilla

Thursday, 14 June 2012

How dates are converted to string in Ax 2009

Hi friends

Today we are going to convert dates in Ax 2009. Below I am going to publish a simple program for that . Paste the following program in Job and go through it.
Display str balanceDate()
{
str day;
str month;
str currentYear;

str datevalue;
int i;
transdate StartMonth;
str year_format;
;
if(salarymonth)
{
StartMonth = Global::dateStartMth(salarymonth);
day = int2str(dayofMth(any2date(StartMonth)));
month = substr(mthname(mthofyr(any2date(StartMonth))),1,3);
currentYear = int2str(year(any2date(StartMonth)));
year_format = substr(currentYear,3,2);
for(i=1; i<=3; i++)
{
switch(i)
{
case 1:
datevalue += day ;
datevalue += ' ';
break;
case 2 :
datevalue += month;
datevalue += ' ';
break;
case 3:
datevalue += year_format;
break;

}
datevalue = datevalue;
}

}
return datevalue;
}

I hope after seeing the program you will understand a lot more about it.


Vivek Chirumamilla

Friday, 8 June 2012

Query using X++ in Ax 2009

Hi Friends,

You know queries are the most easier way to work on than any other statements .

You can derive complex syntax easily by using query.

For first giving us a clear idea we are not going too much deep into the query.

First we have to declare a query by using the following syntax

Query q = new Query();

And we need the following declarations to add datasource, range and to run the query

QueryBuildDataSource qbds;

QueryBuildRange qbr;

QueryRun queryRun;

qbds= q.addDataSource(tablenum(InventTable));
qbds.addSortField(fieldnum(InventTable,ItemId));
qbr = qbds.addRange(fieldnum(InventTable,ItemId));
qbr.value("1104");
qbr1 = qbds.addRange(fieldnum(InventTable,DataAreaId));
qbr1.value(strfmt('(((%3.FromDate >= %1) || (%3.Todate > %1)) && ((%3.Todate<=%2) || (%3.Fromdate<%2)))',Date2StrXpp(LeaveFromDate),
Date2StrXpp(LeaveToDate), q.dataSourceTable(tablenum(InventTable)).name()));

queryRun = new QueryRun(q);
while (queryRun1.next())
{
InventTable= queryRun.get(TableNum(InventTable));

info(strfmt("%1" ,InventTable.ItemId));
}

Vivek Chirumamilla

Thursday, 7 June 2012

date,month tips in Ax 2009

Hi Friends,

Today we are going to have tips on month values and how to effectively use them in Ax 2009.

Here are some tips to use::

To get the next month value use "nextMth(Month)"

To get the previous month value use "prevMth(Month)"

To get the stating month date if the value of a month date is in middle use "datestartmth(Month)"

To get the end month date if the value of a month date is in middle use "dateendmth(Month)"



Vivek Chirumamilla