• Skip to main content
  • Skip to primary sidebar
  • Home
  • About
  • Recommended Readings
    • 2022 Book Reading
    • 2023 Recommended Readings
    • Book Reading 2024
    • Book Reading 2025
  • Supply Chain Management Guide
  • PKM
  • Microsoft Excel

Ali Raza Zaidi

A practitioner’s musings on Dynamics 365 Finance and Operations

Dynamics Ax 2012 Technical Side

How to get exception detail and log into SysExpectionTable. Dynamics Ax 2012

October 25, 2014 by alirazazaidi

When we are working with Document Aif services, any exception is logged in SysExceptionTable. You can excess these details from following link.

Exceptions

There is client requirement that all exception must be log in SysExceptiontable in custom service. I did this with the help of following code snippets which just log the division by Zero exception in SysExceptionTable.

 

 

static void Job19(Args _args)

{

 

InfologData         infoData;

AifInfoLog          aifInfoLog;

container           infologData;

SysInfoLogEnumerator            infoLogEnum;

SysInfologMessageStruct         infoMessageStruct;

 

SysExceptiontable _Excep;

str  ExceptionMessage;

int ab=0;

int test=10;

int result;

 

try

{

aifInfoLog = new AifInfoLog();

result = test / ab;

 

 

}

catch

{

infologData = aifInfoLog.getInfoLogData();

infoLogEnum = SysInfoLogEnumerator::newData(infologData);

while(infoLogEnum.moveNext())

{

//Extract the message from the string

infoMessageStruct = SysInfologMessageStruct::construct(infoLogEnum.currentMessage());

ExceptionMessage +=”\n” + infoMessageStruct.message();

 

 

}

_Excep.Exception =Exception::Error;

_Excep.Description = ExceptionMessage;

_Excep.Module =”Mamoo’s Test”;

_Excep.insert();

 

 

}

 

}

 

Sysexceptiontable

 

 

execute stored procedure with parameters dynamics ax 2012

October 20, 2014 by alirazazaidi

During in one of my assignment, I have to call sql server stored procedure from X++ code. There is little tricky to call stored procedure with parameters. Following code will help me to call stored procedure with Parameters. Consider sp_StudentCreates a stored procedure with three parameters, first two string and last one is date.

private void InsertStudent( StudentDC  _dc)
{
    LoginProperty loginProperty;

OdbcConnection odbcConnection;

Statement statement;

ResultSet resultSet;

LoginProperty myLoginProperty;

str sql, criteria;

int output;

SqlStatementExecutePermission perm;

str myUserName="dynamicworld\\aliraza.zaidi";

str myPassword="xyz";

str myConnectionString;

myConnectionString=strfmt("UID=%1;PWD=%2",myUserName,myPassword);

myLoginProperty = new LoginProperty();

myLoginProperty.setServer("dynamicworld.com");

myLoginProperty.setDatabase("studentDb");

myLoginProperty.setOther(myConnectionString);



//Create a connection to external database.

odbcConnection = new OdbcConnection(myLoginProperty);



if (odbcConnection)

{



    sql = "Execute sp_StudentCreates   '"+_dc.parmFirstName())+"','"+_dc.parmLastMame())+"','"+date2str(_dc.parmDate(),321,DateDay::Digits2,DateSeparator::Hyphen,DateMonth::Digits2,DateSeparator::Hyphen,DateYear::Digits4)+"'";
 info(sql);

//Assert permission for executing the sql string.

perm = new SqlStatementExecutePermission(sql);

perm.assert();



//Prepare the sql statement.

statement = odbcConnection.createStatement();

output = statement.executeUpdate(sql);






statement.close();

}

else

{

error("Failed to log on to the database through ODBC.");
}

}

Connect to an external Database from Dynamics Ax 2012

October 18, 2014 by alirazazaidi

Sometimes we have to communicate with outside of Dynamics Ax with in boundaries of Dynamics ax.

Consider following scenario where I have to communicate with StudentDb in Sql server and insert rows in Student Info. We can do this with odbc connection.

 

 

Now create New AX job and paste following code there

 

 

LoginProperty loginProperty;

OdbcConnection odbcConnection;

Statement statement;

ResultSet resultSet;

LoginProperty myLoginProperty;

str sql, criteria;

int output;

SqlStatementExecutePermission perm;

str myUserName="dynamicworld\\aliraza.zaidi";

str myPassword="abcd";

str myConnectionString;

 

;

 

 

 

 

myConnectionString=strfmt("UID=%1;PWD=%2",myUserName,myPassword);

myLoginProperty = new LoginProperty();

myLoginProperty.setServer("WIN-IKPOSIU2SGD");

myLoginProperty.setDatabase("studentdb");

myLoginProperty.setOther(myConnectionString);

 

//Create a connection to external database.

odbcConnection = new OdbcConnection(myLoginProperty);

 

if (odbcConnection)

{

 

sql ="INSERT INTO ..[StudentInfo]([FirstName],[LastName]) VALUES ('aliraza','zaidi')";

//Assert permission for executing the sql string.

perm = new SqlStatementExecutePermission(sql);

perm.assert();

 

//Prepare the sql statement.

statement = odbcConnection.createStatement();

output = statement.executeUpdate(sql);

 

 

statement.close();

}

else

{

error("Failed to log on to the database through ODBC.");
}




Unable to find appropriate service endpoint information in the configuration object Dynamics Ax 2012.

October 12, 2014 by alirazazaidi

Recently installed the SSRS report extension on my VM Dynamics Ax 2012 R2 CU7. During installation, I continuously found following error message In log files.

 

“Unable to find appropriate service endpoint information in the configuration object”

Later I understand that SSRS reports communicate with AOS through WCF services and WCF service for Dynamics Ax was not running on AOS.

When I opened the Application Integration Framework è Inbound port, I found that BI service was deactivated.

10-12-2014 5-58-16 PM

 

I activate the service, and retry SSRS reporting extension installation, which installed successfully.

 

10-12-2014 11-13-28 PM

Exploring The SalesSalesOrderservice AIF Document Service In Dynamics Ax 2012 R3

October 10, 2014 by alirazazaidi

 

For my session for Integration with Dynamics Ax 2012. I have to consume SalesSalesOrderSerivce. In this article I am configure and consume Sales Order service and share c# code for calling a Sales service and consume.

 

Enable the methods and configure the inbound port. For this you have to go at following link and open AIf Inbound

Aif Link

 

Right click on AIF menu and create a New

set the Name there “ for example I create the port with Name “MySalesOrderService”.

10-10-2014 7-58-10 PM

Click on Service Operations add following one

Selection

Click on arrow button and add these method to service

Selected

Now click on Close button to close it.

Now click to check box to enable data policy button document. Click on it.

enable the Data policy

 

New screen open for all possible fields, Click on Element to sort the list, Enable following fields which are minimum required for Sales Order creation.

Mendatory Selection

 

 

 

Now save it. From port screen enable logging and Click on activate, Wait it will take time to deploy the service on port.

Activate

Info log appear to tell that port is successfully active.

InfoLog

 

Now copy the WSDL url

Wsdl

 

 

Create a new Console application in Visual studio, I am more familiar with C# so I created a console application in C#.

Add new Service reference and set its name “SalesOrderService” and get methods from WSDL.

SalesOrder Service Reference

 

Now Click on Ok button.

 

 

Calling the Create Method.

 


var line = new SalesOrderService.AxdEntity_SalesLine()

{

ItemId = “D0001”,

SalesQty = 42,

SalesUnit = “ea”

SalesOrderService.AxdEntity_InventDim inventDim = new SalesOrderService.AxdEntity_InventDim();
inventDim.InventSiteId = “JS”;

InventDim = new SalesOrderService.AxdEntity_InventDim[] {inventDim};

 

};

 

var order = new SalesOrderService.AxdEntity_SalesTable()

{

CustAccount = “US-003”,

PurchOrderFormNum = “ffg”,

ReceiptDateRequested = DateTime.Now.Date,

 

SalesLine = new SalesOrderService.AxdEntity_SalesLine[] { line }

};

 

//   SalesOrderService. _salesOrder= new SalesOrderService.AxdSalesOrder();

 

 

var orderList = new SalesOrderService.AxdEntity_SalesTable[] { order };

var callContext = new SalesOrderService.CallContext() { Company = “USMF” };

SalesOrderService.SalesOrderServiceClient client = new SalesOrderService.SalesOrderServiceClient();

 

 

//   _salesOrder.SalesTable=orderList;

try

{

client.create(callContext, orderList);

 

 

//  client.create(callContext, orderList);

client.Close();

}

catch

{

client.Abort();

throw;

}

 

Read Method Code

try

{

SalesOrderService.KeyField keyField = new SalesOrderService.KeyField() { Field = “SalesId”, Value = “000767” };

 

 

 

// Create an entity key instance and put in the key field data

 

SalesOrderService.EntityKey entityKey = new SalesOrderService.EntityKey();

 

 

 

entityKey.KeyData = new SalesOrderService.KeyField[1] { keyField };

 

// Create an array of entity keys and put in the previously

 

 

 

SalesOrderService.EntityKey[] entityKeys = new SalesOrderService.EntityKey[1] { entityKey };

 

 

 

 

 

SalesOrderService.SalesOrderServiceClient _Client = new SalesOrderService.SalesOrderServiceClient();

 

SalesOrderService.CallContext _callContext = new SalesOrderService.CallContext();

 

_callContext.Company = “USMF”;

 

 

SalesOrderService.AxdEntity_SalesTable[] _SalesOrder= _Client.read(_callContext, entityKeys);

 

 

SalesOrderService.AxdEntity_SalesTable _SalesTable = _SalesOrder[0];

SalesOrderService.AxdEntity_SalesLine _SalesLineTable = _SalesTable.SalesLine[0];

Console.WriteLine(“Account Num : ” + _SalesTable.CustAccount.ToString());

Console.WriteLine(“Order date  : ” + _SalesTable.ReceiptDateRequested.ToString());

Console.WriteLine(“ItemId  : ” + _SalesLineTable.ItemId.ToString());

Console.WriteLine(“QTy  : ” + _SalesLineTable.SalesQty.ToString());

Console.WriteLine(“Sales Unit  : ” + _SalesLineTable.SalesUnit.ToString());

_Client.Close();

Console.ReadKey();

}

catch

{

//     client.Abort();

throw;

}

 

 

Update Method Call code

 


SalesOrderService.KeyField keyField = new SalesOrderService.KeyField() { Field = "SalesId", Value = "000756" };

 

 

 

// Create an entity key instance and put in the key field data

 

SalesOrderService.EntityKey entityKey = new SalesOrderService.EntityKey();

 

 

 

entityKey.KeyData = new SalesOrderService.KeyField[1] { keyField };

 

// Create an array of entity keys and put in the previously

 

 

 

SalesOrderService.EntityKey[] entityKeys = new SalesOrderService.EntityKey[1] { entityKey };

 

 

 

 

 

SalesOrderService.SalesOrderServiceClient _Client = new SalesOrderService.SalesOrderServiceClient();

 

SalesOrderService.CallContext _callContext = new SalesOrderService.CallContext();

 

_callContext.Company = “USMF”;

 

 

 

SalesOrderService.AxdEntity_SalesTable[] _SalesOrderList = _Client.read(_callContext, entityKeys);

 

 

SalesOrderService.AxdEntity_SalesTable _SalesOrderTable = _SalesOrderList.First();

SalesOrderService.AxdEntity_SalesLine SalesLine = _SalesOrderTable.SalesLine.First();

decimal salesQty = 50;

SalesLine.SalesQty = salesQty;

 

 

 

 

 

 

_Client.update(_callContext, entityKeys, _SalesOrderList);

 

 

Delete method code

 


SalesOrderService.KeyField keyField = new SalesOrderService.KeyField() { Field = "SalesId", Value = "000757" };

 

 

 

// Create an entity key instance and put in the key field data

 

SalesOrderService.EntityKey entityKey = new SalesOrderService.EntityKey();

 

 

 

entityKey.KeyData = new SalesOrderService.KeyField[1] { keyField };

 

// Create an array of entity keys and put in the previously

 

 

 

SalesOrderService.EntityKey[] entityKeys = new SalesOrderService.EntityKey[1] { entityKey };

 

 

 

 

 

SalesOrderService.SalesOrderServiceClient _Client = new SalesOrderService.SalesOrderServiceClient();

 

SalesOrderService.CallContext _callContext = new SalesOrderService.CallContext();

 

_callContext.Company = “USMF”;

 

_Client.delete(_callContext, entityKeys);

 

 

Trouble shooting AIF service.

There are many possible failure of sales service call, You can trouble shoot it from  System Administration section as

Exceptions

During writing code and I got many failures, All exceptions recorded here.

 

ExceptionsForm




List of functions used in Dynamics AX 2012 SSRS Reports Expressions

October 10, 2014 by alirazazaidi

During working in SSRS reports I have to handle division by Zero error for calculating accumulated cost by dividing Amount by Quantity.

 

This expression works for me.

 

IIf(Sum(Fields!xyz.Value) = 0, “N/A”, Sum(Fields!abc.Value) / IIf(Sum(Fields!abc.Value) = 0, 1,Sum(Fields!xvz.Value)))

I did little research on Expressions and function used in these SSRS expressions

 

 

Expressions:

Expressions are used for manipulate or update the value, for example, cost show by dividing amount by Quantity. Rounding of decimal. Similarly Expression can be used to highlight the filed if condition meets. Style font can be changed, even you can uses switch statement, to change the display value of report.

 

Types of Expressions

Globals
Operators – Arithmetic, Comparison, Logical
Common Functions – Text, Date & Time, Math, Inspection, Program Flow, Aggregate, Financial, Conversion, Miscellaneous

We can see each and every one very detail in following.

 

 

Globals

Global expressions executes/works in Page Header and Footer parts only.

ExecutionTime shows date and time at when report executes
PageNumber shows page number of each and every page but allowed only in page header and footer
ReportName displays name of the active report what name we have assigned to the active report
UserId shows current user name like company/alirazazaidi
Language displays language like US-English…

Operators

Arithmetic
^ power of
* multiplication
/ divides two numbers and returns a floating point result
\ divides two numbers and returns a integer result
Mod divides two numbers and returns remainder only
+ adds two numbers and concatenation for two strings
– subtraction and indicates negative value for numeric values
Comparison
Known operators : < <= > >= <> 
Like compares two strings and return true if matched or else returns False. Ex: =Fields!Title.Value Like Fields!LoginID.Value
Is compare two object reference variables Ex: = Fields!Title.Value Is Null
Concatenation
+ and & symbols uses for concatenation
Logical
Known: And, Not, Or 
Xor SELECT * FROM users where firstname = ‘Larry’ XOR lastname = ‘Smith’
AndAlso First condition will check first and if it is true only, goes to next or else it won’t need to check. Because our execution time is saving in a logical operation in which more conditions is combined using AndAlso function.
OrElse same like above

Common Functions

Text

Asc, AscW returns an integer value represents character code corresponding to a character

Chr, chrw returns the character associated with the specified character code

Filter =Filter(Fields!Title.Value,”Pr”,true,0

Format
=Format(Fields!Price.Value, “#,##0.00”), Format(Fields!Date.Value, “yyyy-MM-dd”)

FormatCurrency =formatcurrency(Fields!SickLeaveHours.Value,3)

FormatDateTime =FormatDateTime(Fields!BirthDate.Value,Integer)
Examples:
0 returns 10/10/2014
1 returns Friday, October 10, 2014
2 returns 6/3/2014
3 returns 12:00:00AM
4 returns 00:00

FormatNumber =FormatNumber(Fields!EmployeeID.Value,2)
Examples: 4.00

FormatPercent =”Percentage : ” & formatpercent(Fields!SickLeaveHours.Value)

GetChar =GetChar(Fields!Title.Value,5)

InStr =InStr(Fields!Title.Value,”a

InStrRev =Instrrev(Fields!Title.Value,”a

LCase Change strings into lower case
=Lcase(Fields!Title.Value)

Left Returns left side characters from a string
=Left(Fields!Title.Value,4)

Len Finds length of a string
=Len(Fields!Title.Value)

LSet Returns some length of a string from left
=Lset(Fields!Title.Value,5)

LTrim Trim left side of a string
=Ltrim(” “&Fields!Title.Value)

Mid Returns characters from the mentioned starting position
=Mid(Fields!Title.Value,InSTrRev(Fields!Title.Value,”T

Replace Replaces one string with another
=Replace(Fields!Title.Value,”a”,”A

Right Returns right side characters from a string
=Right(Fields!Title.Value,10)

RSet Returns some length of a string from left
=Rset(Fields!Title.Value,5)

RTrim Trim left side of a string
=Rtrim(Fields!Title.Value & ” “)

Space Specifies some spaces within strings
=Fields!Title.Value & Space(5) & Fields!Title.Value

StrComp Returns a value indicating the result of a string comparison

vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Perform a textual comparison.
string1 is less than string2 -1
string1 is equal to string2 0
string1 is greater than string2 1
string1 or string2 is Null Null

StrConv
=Strconv(Fields!Title.Value,vbProperCase)
=Strconv(Fields!Title.Value,vbLowerCase)
=Strconv(Fields!Title.Value,vbUpperCase)

StrDup Returns a string or object consisting of the specified character repeated the specified number of times.
=StrDup(3,”M”)

StrReverse =StrReverse(Fields!Title.Value)

Trim =Trim(” “& Fields!Title.Value & ” “)

UCase =Ucase(Fields!Title.Value)

Date & Time

CDate Converts a object into date format
=Format(CDate(Fields!BirthDate.Value),”MMMM”)

DateAdd Returns a datetime that is the result of adding the specified number of time interval units to the original datetime.

=dateadd(“m”,12,Fields!BirthDate.Value)

DateDiff Find number of days, months and years between two dates
=datediff(“d”,Fields!BirthDate.Value,Now)

DatePart DatePart(DateInterval.Weekday, CDate(“2009/11/13”), FirstDayOfWeek.Monday) returns 5 (Friday)

DateSerial for first day of the month
=DateSerial(Year(Now), Month(Now), 1)
for the last day of the month
=DateSerial(Year(Now), Month(Now)+1, 0)

DateString Returns string value of system date
=datestring()

DateValue Returns current date

Day Returns day value from date
=day(Fields!BirthDate.Value)

FormatDateTime =FormatDateTime(Fields!BirthDate.Value,Integer)
Examples:
0 returns 6/3/2014
1 returns Friday, June 03, 2014
2 returns 6/3/2014
3 returns 12:00:00AM
4 returns 00:00

Hour =Hour(Fields!BirthDate.Value)

Minute =Minute(Fields!BirthDate.Value)

Month =Month(Fields!BirthDate.Value)

MonthName =MonthName(Month(Fields!BirthDate.Value))

Now Indicates current month
=Now() or =Now

Second =Second(Fields!BirthDate.Value)

TimeOfDay =TimeOfDay()
Returns a date value containing the current time of day according to your system

Timer =Timer()
Returns number of seconds elapsed since midnight

TimeSerial =TimeSerial(24,60,60)
Returns a date value representing a specified hour, minute and second

TimeString =TimeString()
Returns string value representing the current time of day according to your system

TimeValue Returns a date value set to jan 1 of year 1
=TimeValue(Fields!BirthDate.Value)

Today Returns Current date

Weekday Returns an integer value representing day of week
=WeekDay(Fields!BirthDate.Value)

WeekdayName =WeekdayName(Weekday(Fields!BirthDate.Value))
Returns name of the day of week

Year =year(Fields!BirthDate.Value)
Returns year of specified date

Math

Abs Returns the absolute value
=Abs(-2.36)

BigMul Returns multiplication value of two specified numbers
=BigMul(2,3)

Ceiling Returns next highest value
=Ceiling(2.67)

Cos
=Cos(2.33)
Returns cos value for specified number

Cosh
Returns hyperbolic cos value
=Cosh(2.33)

DivRem
=DivRem(23,2,5)

Fix
=Fix(23.89)
Returns integer portion

Floor
=Floor(24.54)
Returns largest integer

Int
=Int(24.78)
Returns integer portion of a number

Log
=Log(24.78)
Returns logarithm value

Log10
=Log10(24.78)
Returns the base 10 logaritm value

Max
=Max(Fields!EmployeeID.Value)
Returns larger value in the specified values

Min
=Min(Fields!EmployeeID.Value)
Returns smaller value in the specified values

Pow
=Pow(Fields!EmployeeID.Value,2)
Returns power of value for specified number

Rnd
=Rnd()
Returns a random number

Round
=Round(43.16)
Returns rounded value to the nearest integer

Sign
=Sign(-34534543)

Sin
=Sin(Fields!EmployeeID.Value)
Returns the sin value

Sinh
=Sinh(Fields!EmployeeID.Value)
Returns the hyperbolic sin value

Sqrt
=Sqrt(Fields!EmployeeID.Value)
Returns square root value

Tan
=Tan(Fields!EmployeeID.Value)
Returns the tan value

Tanh
=Tanh(Fields!EmployeeID.Value)
Returns the hyperbolic tan value

Inspection
IsArray
=IsArray(Fields!EmployeeID.Value)
Returns a boolean value indicating whether the specified object is array or not

IsDate
=IsDate(Fields!BirthDate.Value)
Returns a boolean value indicating whether the specified object is Date or not

IsNothing
=IsNothing(Fields!EmployeeID.Value)
Returns a boolean value depends on specified object is Nothing or not

IsNumeric
=IsNumeric(Fields!EmployeeID.Value)
Returns a boolean value depends on specified object is Numeric value or not

Program Flow

Choose
=CHOOSE(3, “Red”, “Yellow”, “Green”, “White”)
Returns a specific value using index in a list of arguments

IIf
=IIF(Fields!EmployeeID.Value>10,”Yes”,”No
Returns any one value depends on condition

Switch
=Switch(Fields!EmployeeID.Value<10,”Red
Fields!EmployeeID.Value>10,”Green
Evaluates list of expressions

Aggregate

Avg
=Avg(Fields!EmployeeID.Value)
Returns average value for all specified values

Count
=Count(Fields!EmployeeID.Value)
Returns count of all specified values

CountDistinct
=CountDistinct(Fields!EmployeeID.Value)
Returns count of all distinct values

CountRows
=CountRows()
Returns count of rows

First
=First(Fields!EmployeeID.Value)
Returns first for all specified values

Last
=Last(Fields!EmployeeID.Value)
Returns last for all specified values

Max
=Max(Fields!EmployeeID.Value)
Returns max for all specified values

Min
=Min(Fields!EmployeeID.Value)
Returns min for all specified values

StDev
=StDev(Fields!EmployeeID.Value)
Returns standard deviation value

StDevP
=StDevP(Fields!EmployeeID.Value)
Returns Population standard deviation value

Sum
=Sum(Fields!EmployeeID.Value)
Returns sum of all values

Var
=Var(Fields!EmployeeID.Value)
Returns variance of all values

VarP
=Var(Fields!EmployeeID.Value)
Returns population variance of all values

RunningValue
=RunningValue(Fields!EmployeeID.Value,sum,nothing)
Returns running aggregate of the specified
expression

Financial

DDB DDB (Double Declining Balance) method computes depreciation of an asset for a specified period.
Syntax: DDB (Cost, Salvage, life, period, factor)

FV FV (Future Value) of an investment based on periodic, constant payments and a constant interest rate.
Syntax: FV (rate, nper, pmt, pv, type)

IPmt IPmt (Interest Payment) for a given period for an investment based on periodic, constant payment and a constant interest rate
IPMT (rate, per, nper, pv, fv, type)

IRR IRR (Interest Rate of Return) for a series of cash flows represented by the numbers in values.
IRR(values,guess)

MIRR MIRR ( Modified internal rate of return ) for a series of periodic cash flows
MIRR(values,finance_rate,reinvest_rate)

NPer Returns the number of periods for an investment based on periodic, constant payments and a constant interest rate.
NPER (rate, pmt, pv, fv, type)

NPV Calculates the net present value of an investment by using a discount rate and a series of future payments (negative values) and income (positive values).
Syntax: NPV(rate,value1,value2, …)

Pmt Calculates the payment for a loan based on constant payments and a constant interest rate.
PMT(rate,nper,pv,fv,type)

PPmt Returns the payment on the principal for a given period for an investment based on periodic, constant payments and a constant interest rate.
PPMT(rate,per,nper,pv,fv,type)

PV Returns the present value of an investment. The present value is the total amount that a series of future payments is worth now. For example, when you borrow money, the loan amount is the present value to the lender.
PV(rate,nper,pmt,fv,type)

Rate Returns the interest rate per period of an annuity. RATE is calculated by iteration and can have zero or more solutions.
RATE(nper,pmt,pv,fv,type,guess)

SLN Returns the straight-line depreciation of an asset for one period.
SLN(cost,salvage,life)

SYD Returns the sum-of-years’ digits depreciation of an asset for a specified period.
SYD(cost,salvage,life,per)

Conversion

CBool Convert to boolean
=CBool(fields!EmployeeID.Value)
CByte Convert to byte
CChar Convert to char
CDate Convert to date
CDbl Convert to double
CDec Convert to decimal
CInt Convert to integer
CLng Convert to long
CObj Convert to object
CShort Convert to short
CSng Convert to single
CStr Convert to string
Fix =Fix(32.342143)
Returns integer portion of a number
Hex =Hex(Fields!EmployeeID.Value)
Returns a hexadecimal value of a number
Int =Int(43.44)
Returns integer portion of a number
Oct =Oct(Fields!EmployeeID.Value)
Returns a octal value of a number
Str =Str(Fields!EmployeeID.Value)
Returns string value of a number
Val =Val(“32.43”)
Returns numeric value in string format

Miscellaneous

Previous =Previous(Fields!EmployeeID.Value)
Returns the previous value

 

Reference : http://krishhdax.blogspot.com/2012/10/expressions-or-functions-used-in-ax.html

Creating and consuming Custom Document Service in Dynamics Ax 2012 R3

September 15, 2014 by alirazazaidi

For one of Presentation on AIF, I build a custom Document Service based on custom table. To avoid any validation constraints I made a very simple custom table “StudentInfoTable”.

FieldName dataType
Roll Number string
FistName string
LastName string
Address string
DateOfBirth date.

 

Create a Unique Index on FirstName field, so Read and find method of custom Document service works fine.

 

 

In AOT under Query Node with Name AxdStudentInfo, create a new DataSource and add StudentInfoTable. Right click on field and set Dynamic Property to Yes

 

Query

 

Now right click on “StudentInfoTable” Node and set its Update properties to true, so Update methods will created against this query object

 

UpdateQuery

 

Now in Development environment from top menu click on AIF frame and then select on Create Document Service and click on it. For this result in running a Wizard

Menu

 

 

Select following options from Wizard, select the query which we create above mentioned drop down. Name the Document Name

 

9-14-2014 10-04-05 AM

Press Next button, from the next button check all the checkbox as per following screen shot.

9-14-2014 10-05-12 AM

Press on Next Button

9-14-2014 10-08-52 AM

Press on Generate button.

9-14-2014 10-12-39 AM

Press On Finished button.

There is possibility of errors in generated code, You can find complete code generated with wizard in private project in Dynamics Ax.

Private Project for Document Services

Right click on AxdStudentInfo and compile again.

You have delete two methods  cacheObject and cacheRecordRecord in AxStudentInfoTable and compile the whole project.

 

Now right click on StudentInfoService and set namespace

http://schemas.Student.com/ServiceContracts

Service reference

Now create a right on Service group Node and create a new service group.

 

Service Group

Drag and drop service node under Student InfoService group. So  Student Service will be available for in side service group.

 

Now generate Inc CIL or right click on StudentInfoServicegroup and click deploy

 

Deploy Service Group

 

 

 

 

 

 

After successful deployment you may find following info box

 

Service InfoBox

 

 

 

 

Now open a new work space and go at System Administration module and open in bound port under Application integration framework

In Bound Port


 

 

And Open Application Inbound framework

 

Address

Copy WSDL URL In my case it is

 

http://WIN-IKPOSIU2SGD:8101/DynamicsAx/Services/StudentInfoServiceGroup

 

now open Visual studio Project and create a new Console project I am more comfortable with C#.

Console

 

 

 

From Solution explore right click and add Service reference

ServiceReference2

 

 

Now we can use following code to create, Read, Update and delete methods

 

Create method

 

 

  StudentInfoRef.AxdEntity_StudentInfoTable _StudentInfo = new StudentInfoRef.AxdEntity_StudentInfoTable();

StudentInfoRef.AxdStudentInfo _Student = new StudentInfoRef.AxdStudentInfo();

_Student.StudentInfoTable = new StudentInfoRef.AxdEntity_StudentInfoTable[1] { _StudentInfo };

 

_StudentInfo.FirstName = "Ali";

_StudentInfo.LastName = " Raza";

_StudentInfo.Address = " Lahore";

_StudentInfo.DateOfBirth = new DateTime(1979, 4, 6);

StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient();

StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext();

_callContext.Company = "USSI";

StudentInfoRef.EntityKey[] entityKeys = _Client.create(_callContext, _Student);

You can see create function works fine.
TableExploreCreate
In above mentioned code, Create method take two parameter, first is Call context, In Call context variable we can define legal entity where data will be inserted.

 

 

Read Method

 

Read method use EntityKey for searching criteria for example we want to search Student with First Name Ali following code will works for Us.

Read method works on keyField value. It is recommend that you will search records on the bases of Unique indexed based field.

 

 

 

StudentInfoRef.KeyField keyField = new StudentInfoRef.KeyField() { Field = "FirstName", Value = "Ali2" };

 

// Create an entity key instance and put in the key field data

StudentInfoRef.EntityKey entityKey = new   StudentInfoRef.EntityKey();

 

entityKey.KeyData   = new   StudentInfoRef.KeyField[1] { keyField };

// Create an array of entity keys and put in the previously

 

StudentInfoRef.EntityKey[] entityKeys = new StudentInfoRef.EntityKey[1] { entityKey };

 

 

StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient();

StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext();

_callContext.Company = "USSI";

 

StudentInfoRef.AxdStudentInfo _StudentInfo = _Client.read(_callContext, entityKeys);

 

 

StudentInfoRef.AxdEntity_StudentInfoTable _StudentInfoTable = _StudentInfo.StudentInfoTable[0];

 

Console.WriteLine("First Name :" + _StudentInfoTable.FirstName);

Console.WriteLine("Last Name :" + _StudentInfoTable.LastName);

Console.WriteLine("Address :" + _StudentInfoTable.Address);

 

Console.ReadLine();

 

 

 

 

 

 

Update Method

Update in Document is two step process, first step to read the record based on field and second step to update the record which is return as result.

 

 

For example I want to update Address and Last Name of student. Following code works for me.

 

 

 

StudentInfoRef.KeyField keyField = new StudentInfoRef.KeyField() { Field = "FirstName", Value = "Ali2" };

 

// Create an entity key instance and put in the key field data

StudentInfoRef.EntityKey entityKey = new StudentInfoRef.EntityKey();

 

entityKey.KeyData = new StudentInfoRef.KeyField[1] { keyField };

// Create an array of entity keys and put in the previously

 

StudentInfoRef.EntityKey[] entityKeys = new StudentInfoRef.EntityKey[1] { entityKey };

 

 

StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient();

StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext();

_callContext.Company = "USSI";

 

StudentInfoRef.AxdStudentInfo _StudentInfo = _Client.read(_callContext, entityKeys);

 

 

StudentInfoRef.AxdEntity_StudentInfoTable _StudentInfoTable = _StudentInfo.StudentInfoTable.First();

 

_StudentInfoTable.Address = "Lahore";

_StudentInfoTable.LastName = "Zaidi";

_StudentInfoTable.action = StudentInfoRef.AxdEnum_AxdEntityAction.update;

_StudentInfoTable.actionSpecified = true;

_Client.update(_callContext, entityKeys, _StudentInfo);

 

 

 

 

Delete Method

 

Delete Method works for same way, Send entity keys and call for Delete method.

 

StudentInfoRef.KeyField keyField = new StudentInfoRef.KeyField() { Field = "FirstName", Value = "Ali2" };

 

// Create an entity key instance and put in the key field data

StudentInfoRef.EntityKey entityKey = new StudentInfoRef.EntityKey();

 

entityKey.KeyData = new StudentInfoRef.KeyField[1] { keyField };

// Create an array of entity keys and put in the previously

 

StudentInfoRef.EntityKey[] entityKeys = new StudentInfoRef.EntityKey[1] { entityKey };

 

 

StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient();

StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext();

_callContext.Company = "USSI";

_Client.delete(_callContext, entityKeys);


 

 

 

Clear the Cache on all clients Dynamics Ax 2012

August 10, 2014 by alirazazaidi

Last week I post a solution to problem of old code on Dynamics Ax 2012 Client, That work for single client and it is not possible to clear cache on manually on every client. Later I found better solution to reset the client cache at AOS. Reference is

Reset program cache file for all clients


According to that reference we have to reset the GUID, so all Clients have to reset its cache, this method required AOS restart.

static void ResetAUC(Args _args)
{
#AiF
SysSQMSettings _Settings;
;
ttsbegin;
update_recordset _Settings setting GlobalGUID = str2Guid(#EmptyGuidString);
ttscommit;
info("Now we have to Restart the AOS Service to use a new GlobalGUID.");
}

Its works for me.

Dynamics Ax 2012 Error Code 90, Unable to connect to database

August 5, 2014 by alirazazaidi

My friend Bashir Ahmad Malik got following error during start up dynamics Ax service.

 

“The Microsoft Dynamics AX Object Server 6.2$01-MicrosoftDynamicsAX service terminated with service-specific error Code 90.
Suspect state of SQL Server database is a state when you are unable to connect to the database. “

 

During trouble shooting we find following root causes.

 

  • database is corrupted
  • database files are being “opened” or held by some process (operating system, other program(s)…)
  • not enough disk space for SQL Server
  • insufficient memory (RAM) for SQL Server
  • unexpected SQL Server shutdown caused by power failure

 

we solve this problem by following Sql Script.

  1. Connect database server with Microsoft SQL Server Management Studio.
  2. Execute the following SQL script in given order:

NOTE: replace [DatabaseName] with your database name

-- This query will rollback any transaction which is running on that database

-- and bring SQL Server database in a "single user" mode

ALTERDATABASEMicrosoftDynamicsAX SETSINGLE_USER WITHROLLBACKIMMEDIATE

 

-- Marking database READ_ONLY, disable logging,

-- and limiting access only to members of the sysadmin fixed server role

ALTERDATABASEMicrosoftDynamicsAX SETEMERGENCY

 

-- Checks the logical and physical integrity of all the objects in the specified database

DBCC checkdb(MicrosoftDynamicsAX)

 

-- In case of simple failure then we can use allow data loss option to recover Database

 

--  DBCC CheckDB (MicrosoftDynamicsAX, REPAIR_ALLOW_DATA_LOSS)

 

-- Set database accessibility to it's original state, allowing all logins

ALTERDATABASE MicrosoftDynamicsAX SETMULTI_USER

EXEC sp_resetstatus MicrosoftDynamicsAX


reference : http://social.technet.microsoft.com/wiki/contents/articles/25820.repair-a-suspect-database-in-sql-server.aspx

Dynamics Ax 2012 Client cache problem

August 3, 2014 by alirazazaidi

A few days ago, I was working on Dynamics Ax 2012 customization. When I shifted code to QA server, Compile, Generate CIL, but no changes display on client. I was shocked, latest code working fine on my machine but why it is not working on QA server. AOT shows the latest code. During troubleshooting I found that it is due to Client Cache.  For this I have to delete cache files form cache folder. AX cache files have “auc” extension.

 

I found auc files from following folder

C:\Users\aliraza.zaidi\AppData\Local\

 

I perform following steps.

  1. Close Client on machine.
  2. Stop AOS service.
  3. Delete all auc files from local cache folder.
  4. Restart AOS.
  5. Open client.

 

I found latest code working fine on QA server.

« Previous Page
Next Page »

Primary Sidebar

About

I am Dynamics AX/365 Finance and Operations consultant with years of implementation experience. I has helped several businesses implement and succeed with Dynamics AX/365 Finance and Operations. The goal of this website is to share insights, tips, and tricks to help end users and IT professionals.

Legal

Content published on this website are opinions, insights, tips, and tricks we have gained from years of Dynamics consulting and may not represent the opinions or views of any current or past employer. Any changes to an ERP system should be thoroughly tested before implementation.

Categories

  • Accounts Payable (2)
  • Advance Warehouse (2)
  • Asset Management (3)
  • Azure Functions (1)
  • Books (6)
  • Certification Guide (3)
  • Customization Tips for D365 for Finance and Operations (62)
  • D365OF (59)
  • Data Management (1)
  • database restore (1)
  • Dynamics 365 (58)
  • Dynamics 365 for finance and operations (135)
  • Dynamics 365 for Operations (165)
  • Dynamics AX (AX 7) (134)
  • Dynamics AX 2012 (274)
  • Dynamics Ax 2012 Forms (13)
  • Dynamics Ax 2012 functional side (16)
  • Dynamics Ax 2012 Reporting SSRS Reports. (31)
  • Dynamics Ax 2012 Technical Side (52)
  • Dynamics Ax 7 (65)
  • Exam MB-330: Microsoft Dynamics 365 Supply Chain Management (7)
  • Excel Addin (1)
  • Favorites (12)
  • Financial Modules (6)
  • Functional (8)
  • Implementations (1)
  • Lifecycle Services (1)
  • Logseq (4)
  • Management Reporter (1)
  • Microsoft Excel (4)
  • MS Dynamics Ax 7 (64)
  • MVP summit (1)
  • MVP summit 2016 (1)
  • New Dynamics Ax (19)
  • Non Defined (9)
  • Note taking Apps (2)
  • Obsidian (3)
  • Personal Knowledge Management (2)
  • PKM (13)
  • Power Platform (6)
  • Procurement (5)
  • procurement and sourcing (5)
  • Product Information Management (4)
  • Product Management (6)
  • Production Control D365 for Finance and Operations (10)
  • Sale Order Process (10)
  • Sale Order Processing (9)
  • Sales and Distribution (5)
  • Soft Skill (1)
  • Supply Chain Management D365 F&O (3)
  • Tips and tricks (278)
  • Uncategorized (165)
  • Upgrade (1)
  • Web Cast (7)
  • White papers (4)
  • X++ (7)

Copyright © 2025 · Magazine Pro On Genesis Framework · WordPress · Log in