X++ code to Split the file name from the file path

// If the file path comes from the dialog , it automatically works ,else you need to Specify '\\'
-----------------------------------------------------------------------------------

static void RB_FileNameSplit(Args _args)
{

Filename path;
FileName fileName;
Filename name;
Filename extention;
Str str_filename;
;
fileName = "c:\\Documents and Settings\\balakrishnanr\\Desktop\\practicefile.xls";
[path, name, extention] = fileNameSplit(fileName);
if (!name)
{
str_filename = '';
}

str_filename = name + extention;

print str_filename;
Pause;

}

X++ code to send email from AX

// One line code to send the email from AX......

static void RB_mailthroughSysInet(Args _args)
{

SysINetMail m = new SysINetMail();
m.sendMailAttach('ramesh.bala@gmail.com','','Hi','hi',true,'','');
Print "success";
Pause;
}

X++ code to export the file from AX

static void RB_ExportAs_csvFileCommaIo(Args _args)
{
CommaIo fileOut;
//based on the extension it will export the file from AX .
FileName fileName = "c:\\Customers.csv";
CustTable custTable;
;
#File

fileOut = new CommaIo(filename, #io_write);

if (fileOut)
{
while select custTable
{
fileOut.write(custTable.accountNum,
custTable.name,
custTable.custGroup,
custTable.currency);
}
}
}

Object Server 01: Internal Error occurred executing stored procedures when creating session for the AOS.

If you are getting this error in the Event Viewer during Upgradation of AX 2009
Object Server 01: Internal Error occurred executing stored procedures when creating session for the AOS.

To solve that, I've just delete CREATESERVERSESSIONS and CREATEUSERSESSIONS
stored procedures, and run follow scripts:

USE [DB NAME]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[CREATESERVERSESSIONS] @aosId varchar(50), @version
int, @instanceName nvarchar(50), @recid bigint, @maxservers int, @status
int, @loadbalance int, @workload int, @serverid int OUTPUT as declare @first
as varchar(50) declare @max_val as int begin select top 1 @first = SERVERID
from SYSSERVERSESSIONS WITH (UPDLOCK, READPAST) where STATUS = 0 and AOSID
= @aosId and INSTANCE_NAME = @instanceName if (select count(SERVERID) from
SYSSERVERSESSIONS where SERVERID IN (@first)) > 0 begin update
SYSSERVERSESSIONS set AOSID = @aosId, VERSION = @version, INSTANCE_NAME =
@instanceName, LOGINDATETIME = dateadd(ms, -datepart(ms,getutcdate()),
getutcdate()), LASTUPDATEDATETIME = dateadd(ms, -datepart(ms,getutcdate()),
getutcdate()), STATUS = @status, WORKLOAD = @workload where SERVERID IN
(@first) and ((select count(SERVERID) from SYSSERVERSESSIONS where
STATUS = 1 and LOADBALANCE = 0) < @maxservers) if @@ROWCOUNT = 0 select
@serverid = 0 else select @serverid = @first end else begin if (select
count(SERVERID) from SYSSERVERSESSIONS WITH (UPDLOCK) where STATUS = 1
and LOADBALANCE = 0) >= @maxservers select @serverid = 0 else begin if
(select count(SERVERID) from SYSSERVERSESSIONS) = 0 select @max_val = 1 else
select @max_val = max(SERVERID)+1 from SYSSERVERSESSIONS insert into
SYSSERVERSESSIONS(SERVERID, AOSID, INSTANCE_NAME, VERSION, LOGINDATETIME,
LASTUPDATEDATETIME, STATUS, RECID, LOADBALANCE, WORKLOAD) values(@max_val,
@aosId, @instanceName, @version, dateadd(ms, -datepart(ms,getutcdate()),
getutcdate()), dateadd(ms, -datepart(ms,getutcdate()), getutcdate()),
@status, @recid, @loadbalance, @workload) select @serverid = @max_val end
end end

-------------------------------------------------------------------------------------------------------------------------------------------------

USE [DB NAME]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[CREATEUSERSESSIONS] @clientType int, @sessionType
int, @serverid int, @versionid int, @userid varchar(5), @lanExt varchar(10),
@manExt varchar(10), @sid varchar(124), @recid bigint, @startId int,
@maxusers int, @licenseType int, @masterId int, @maxClientId int, @sessionid
int OUTPUT, @loginDateTime datetime OUTPUT as declare @return_val as int
declare @first as int declare @max_val as int begin select @sessionid = -1
select @max_val = -1 select @loginDateTime =
dateadd(ms, -datepart(ms,getutcdate()), getutcdate()) if(not exists(select *
from SYSSERVERSESSIONS WITH (NOLOCK) where SERVERID = @serverid AND Status =
1)) begin select @sessionid = -2 return end select @first = min(SESSIONID)
from SYSCLIENTSESSIONS WITH (UPDLOCK,READPAST) where STATUS = 0 and
SESSIONID > @maxClientId and SESSIONID <> @masterId if (select count(*) from
SYSCLIENTSESSIONS where SESSIONID IN (@first)) > 0 begin if (@licenseType =
0) begin update SYSCLIENTSESSIONS set STATUS = 1, VERSION = @versionid,
SERVERID = @serverid, USERID = @userid, LOGINDATETIME = @loginDateTime, SID
= @sid, USERLANGUAGE = @lanExt, HELPLANGUAGE = @manExt, CLIENTTYPE =
@clientType, SESSIONTYPE = @sessionType where SESSIONID IN (@first) end else
if (@licenseType = 1) begin update SYSCLIENTSESSIONS set STATUS = 1, VERSION
= @versionid, SERVERID = @serverid, USERID = @userid, LOGINDATETIME =
@loginDateTime, SID = @sid, USERLANGUAGE = @lanExt, HELPLANGUAGE = @manExt,
CLIENTTYPE = @clientType, SESSIONTYPE = @sessionType where SESSIONID IN
(@first) and ((select count(SESSIONID) from SYSCLIENTSESSIONS where
CLIENTTYPE = @clientType and ((STATUS = 1) or (STATUS = 2))) < @maxusers)
end else if (@licenseType = 2) begin update SYSCLIENTSESSIONS set STATUS =
1, VERSION = @versionid, SERVERID = @serverid, USERID = @userid,
LOGINDATETIME = @loginDateTime, SID = @sid, USERLANGUAGE = @lanExt,
HELPLANGUAGE = @manExt, CLIENTTYPE = @clientType, SESSIONTYPE = @sessionType
where SESSIONID IN (@first) and ( (select count(SESSIONID) from
SYSCLIENTSESSIONS where CLIENTTYPE = @clientType and (USERID = @userid) and
((STATUS = 1) or (STATUS = 2))) > 0 or (select count(distinct USERID) from
SYSCLIENTSESSIONS where CLIENTTYPE = @clientType and ((STATUS = 1) or
(STATUS = 2))) < @maxusers ) end if @@ROWCOUNT = 0 select @sessionid = 0
else select @sessionid = @first end else begin if (@licenseType = 1) begin
if (select count(SESSIONID) from SYSCLIENTSESSIONS where CLIENTTYPE =
@clientType and ((STATUS = 1) or (STATUS = 2))) >= @maxusers select
@sessionid = 0 end else if (@licenseType = 2) begin if ( ((select
count(distinct USERID) from SYSCLIENTSESSIONS where CLIENTTYPE = @clientType
and ((STATUS = 1) or (STATUS = 2))) >= @maxusers) and ((select
count(SESSIONID) from SYSCLIENTSESSIONS where CLIENTTYPE = @clientType and
(USERID = @userid) and ((STATUS = 1) or (STATUS = 2))) = 0) ) select
@sessionid = 0 end if (@sessionid = -1) or (@licenseType = 0) begin if
(select count(SESSIONID) from SYSCLIENTSESSIONS WITH (UPDLOCK) where STATUS
= 0 or STATUS = 1 or STATUS = 2 or STATUS = 3) = 0 select @max_val =
@startId else select @max_val = max(SESSIONID)+1 from SYSCLIENTSESSIONS WITH
(UPDLOCK) if (@max_val > 65535) select @sessionid = -3 else begin insert
into SYSCLIENTSESSIONS(SESSIONID, SERVERID, VERSION, LOGINDATETIME, USERID,
SID, USERLANGUAGE, HELPLANGUAGE, CLIENTTYPE, SESSIONTYPE, RECID,
CLIENTCOMPUTER, STATUS) values(@max_val, @serverid, @versionid,
@loginDateTime, @userid, @sid, @lanExt, @manExt, @clientType, @sessionType,
@recid, '', 1) if @@ROWCOUNT = 0 select @sessionid = -1 else select
@sessionid = @max_val end end end end

Troubleshooting during AX2009 Upgrdation

Sometimes during an upgrade to Dynamics AX 2009, you get the following errors -

Symptoms

Object Server 05: The database reported (session 1 (-AOS-)): [Microsoft][SQL Native Client][SQL Server]Invalid object name 'SYSSERVERSESSIONS'.. The SQL statement was: "SELECT A.SERVERID,A.AOSID,A.INSTANCE_NAME,A.VERSION,A.LOGINDATETIME,A.LOGINDATETIMETZID,A.STATUS,A.LOADBALANCE,A.WORKLOAD,A.LASTUPDATEDATETIME,A.LASTUPDATEDATETIMETZID,A.RECVERSION,A.RECID FROM SYSSERVERSESSIONS A WHERE (STATUS=?)"

Object Server 05: SQL diagnostics: [Main Microsoft Dynamics Application Object Server Session]Unable to report problem. Attempted to open message 310.

Object Server 05: Dialog issued for client-less session 1: Cannot select a record in Current AOS instances (SysServerSessions). ServerId: 0, .
The SQL database has issued an error.

Object Server 05: The database reported (session 1 (-AOS-)): [Microsoft][SQL Native Client][SQL Server]Invalid object name 'SYSCLIENTSESSIONS'.. The SQL statement was: "SELECT A.SESSIONID,A.SERVERID,A.VERSION,A.LOGINDATETIME,A.LOGINDATETIMETZID,A.STATUS,A.USERID,A.SID,A.USERLANGUAGE,A.HELPLANGUAGE,A.CLIENTTYPE,A.SESSIONTYPE,A.CLIENTCOMPUTER,A.RECVERSION,A.RECID FROM SYSCLIENTSESSIONS A WHERE (SERVERID=?)"

Object Server 05: Internal Error occurred executing stored procedure when creating session for the AOS.

Resolution

Make sure to backup your database before running this below script

Run this SQL and restart the AOS

update SqlSystemVariables set value = value - 1 where parm = 'systabversion'

The kernel uses the SYSTABVERSION parameter value in the SqlSystemVariables table to synchronize its list with the DB. By running the below query you tricked the AOS to think that the DB is outdated and during startup it created those missing tables.

X++ code to copy file from one location to another location

static void WinApiClassestocopythefile(Args _args)
{
#avifiles
boolean present;
SysOperationProgress simpleProgress;
int i;
;

// startlengthyoperation();
SimpleProgress = SysOperationProgress::newGeneral(#aviupdate, 'Simple', 100);
if(WinAPI::fileExists("D:\\Ramesh_Ax_Docs\\AX Books\\AXInstallationGuide.pdf"))
{
for (i=1; i<=100; i++)
{
simpleProgress.incCount();
simpleprogress.setText(strfmt("%1% Of File is being Copied",i));
sleep(200);
}
WinAPI::copyFile("D:\\Ramesh_Ax_Docs\\AX Books\\AXInstallationGuide.pdf","D:\\Ramesh_Ax_Docs\\AXInstallationGuide.pdf",true);
Simpleprogress.kill();
}
else
{
info("This file does not exist");
}
info("The file has been Copied :)");
info(strfmt("The filesize is %1",WinApi::fileSize("D:\\Ramesh_Ax_Docs\\AXInstallationGuide.pdf")));
info(WinAPI::getComputerName());
//endlengthyoperation();
}

X++ Code to add new components in AOT

static void AOTCreatequery(Args _args)
{
// This function will add a new Form to the AOT.
treeNode treeNode;
xInfo xInfo = new xInfo();
;
treeNode = xInfo.rootNode();
treeNode = treeNode::findNode("Forms"); // You can use all the AOT components.
treeNode.AOTadd("Praveen");
treenode.AOTsave();
}

X++ to connect the database in AX 2009

Void DBConnection()
{
LoginProperty LP = new LoginProperty();
OdbcConnection myConnection;
Statement myStatement;
ResultSet myResult;
#define.Constring("DSN=DSNName;UID=Username;PWD= ****")

;

LP.setOther(#Constring); //New line added by ramesh
myConnection = new OdbcConnection(LP);
myStatement = myConnection.createStatement();
myResult=myStatement.executeQuery("SELECT * from tablename");

while (myResult.next())
{

Name = any2str(myResult.getString(1));
Id = any2str(myresult.getString(2));
Date = any2date(myresult.getString(3));
}
}

Install and Configure Zpl Printer on D365 F&O

  Setup Zpl Printer On D365 F&O Posted on Recently, I have had an opportunity review the possibilities to print license plates within D3...