Hi guys!
I am gonna show you how to save a Dynamics Ax Report to PDF file.
We are going to use de getTempPath() method from WinApi class for getting the tmp directory.
static void saveProdId()
{
ReportRun report;
Args args;
ProdBOM prodBOM;
FilePath path;
ProdId prodId;
;
path = WinAPI::getTempPath();
prodId= 'ProdIdNumber';
select prodBOM where prodBOM.ProdId == prodId
&& prodBOM.ProdLineType == BomType::Vendor;
args = new Args();
args.name(reportStr(SomeReport));
args.record(prodBOM);
report = ClassFactory.reportRunClass(args);
report.printJobSettings().setTarget(PrintMedium::File);
report.printJobSettings().preferredTarget(PrintMedium::File);
report.printJobSettings().format(PrintFormat::PDF);
report.printJobSettings().fileName(path + prodId + '.pdf');
report.query().interactive(false);
report.run();
}
See you!
Tuesday, November 28, 2017
Saving a Dynamics Ax Report to PDF
Labels:
Dynamics Ax 2012 R3,
getTempPath,
getTempPath(),
PDF,
printJobSettings,
Report,
WinApi,
X++
Monday, November 13, 2017
Using Infolog Ax 2012 R3
In this post you can learn how to use InfoLog class for sending a beautiful and professional messages in Dynamics Ax, however final user could not notice your effort.
static void testJCAinfo(Args _args)
{
SetPrefix("Grandpa");
SetPrefix("Dad");
SetPrefix("Me");
Infolog.add(Exception::Warning,"Puppy");
}
And the result is:
static void testJCAinfo(Args _args)
{
SetPrefix("Grandpa");
SetPrefix("Dad");
SetPrefix("Me");
Infolog.add(Exception::Warning,"Puppy");
}
And the result is:
Now you have the power to agroup the info messages in Ax, but you can give more functionally if you want. check the code below
static void Test(Args _args)
{
SysInfoAction_FormRun infoAction = SysInfoAction_FormRun::newFormName(formStr(EcoResProductDetailsExtended)); //Which form?
infoAction.parmCallerBuffer(InventTable::find('TEST5')); // which record??
Infolog.add(Exception::Warning,"El artículo no está propiamente configurado",'',infoAction);
}
First, we got the itemid with errors (TEST5)
In the message infolog we select the message
Notice a new button is appear automatically, and if you click on it, Ax shows you the EcoResProductDetailsExtended with the TEST5 Item.
Wednesday, November 1, 2017
Using RoundUp and RoundDown
Sometimes we would need to round a number, in this case you can use global method roundUp or rounDown.
static void roundExample()
{
info(num2expstr(roundUp(6.5 ,1)));
}
The result is 7,
This morning I was in trouble using this function... the result was 6 instead 7 such as if I would using roundDown, some minutes later I notice I was tryng rounding a negative number LOL.
Thursday, October 19, 2017
Creating a purchPackingSlip from Code X++
Hi there!
In this code i'm showing you how to create a purch packing slip from code...
private void createPackingSlip(PurchId _purchId,packingSlipId _packingSlipId, Qty _qtyToReceive)
{
PurchFormLetter purchFormLetter;
PurchFormletterParmData purchFormLetterParmData;
PurchParmUpdate purchParmUpdate;
PurchParmTable purchParmTable;
PurchParmLine purchParmLine;
PurchTable purchTable;
PurchLine purchLine;
PurchId purchId;
Num packingSlipId;
Qty qtyToReceive;
purchId = _purchId;
packingSlipId = _packingSlipId;
purchTable = PurchTable::find(purchId);
qtyToReceive = _qtyToReceive;
ttsBegin;
// Create PurchParamUpdate table
purchFormLetterParmData = PurchFormletterParmData::newData(
DocumentStatus::PackingSlip,
VersioningUpdateType::Initial);
purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
purchFormLetterParmData.createData(false);
purchParmUpdate = purchFormLetterParmData.parmParmUpdate();
// Set PurchParmTable table
purchParmTable.clear();
purchParmTable.TransDate = SystemDateGet();
purchParmTable.Ordering = DocumentStatus::PackingSlip;
purchParmTable.ParmJobStatus = ParmJobStatus::Waiting;
purchParmTable.Num = packingSlipId;
purchParmTable.PurchId = purchTable.PurchId;
purchParmTable.PurchName = purchTable.PurchName;
purchParmTable.DeliveryName = purchTable.DeliveryName;
purchParmTable.DeliveryPostalAddress = purchTable.DeliveryPostalAddress;
purchParmTable.OrderAccount = purchTable.OrderAccount;
purchParmTable.CurrencyCode = purchTable.CurrencyCode;
purchParmTable.InvoiceAccount = purchTable.InvoiceAccount;
purchParmTable.ParmId = purchParmUpdate.ParmId;
purchParmTable.insert();
// Set PurchParmLine table
select purchLine
where purchLine.PurchId == _purchId;
purchParmLine.InitFromPurchLine(purchLine);
purchParmLine.ReceiveNow = _qtyToReceive;
purchParmLine.ParmId = purchParmTable.ParmId;
purchParmLine.TableRefId = purchParmTable.TableRefId;
purchParmLine.setQty(DocumentStatus::PackingSlip, false, true);
purchParmLine.setLineAmount();
purchParmLine.insert();
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.transDate(systemDateGet());
purchFormLetter.proforma(false);
purchFormLetter.specQty(PurchUpdate::All);
purchFormLetter.purchTable(purchTable);
purchFormLetter.parmParmTableNum(purchParmTable.ParmId);
purchFormLetter.parmId(purchParmTable.ParmId);
purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
purchFormLetter.run();
ttsCommit;
}
I hope this will be useful.
Labels:
AX2012,
Dynamics Ax 2012 R3,
PackingSlipId,
X++
Thursday, January 7, 2016
Validating user domain password in Ax 2012 (AxaptaUserManager)
Hi there!
I think it is time to let you know how you can validate the user domain password in Ax 2012 R3, also it works on Ax 2009.
We need to create an instance of AxaptaUserManager... let's codify
01 static void JC(Args _args)
02 {
03
04 AxaptaUserManager axUserManager;
05 UserInfo userInfo;
06 ;
07
08 userInfo = xUserInfo::find(false, curuserId());
09
10 axUserManager = new AxaptaUserManager();
11
12 if (axUserManager.validatePassword(userInfo.networkAlias , userInfo.NetworkDomain, "4V3rYC0mpl3xPa$$w0rd!!"))
13 {
14 info ("Welcome to the jungle!!!");
15 }
16 else
17 {
18 info ("Intruder");
19 }
20
21}
In the line number 12, the last parameter of the code is a very complex password of the user of the first parameter in the domain specified in the second parameter, return true if the password is correct!
I do not want to insult your intelligence, so I do not profundize on the topic, LOL
I think it is time to let you know how you can validate the user domain password in Ax 2012 R3, also it works on Ax 2009.
We need to create an instance of AxaptaUserManager... let's codify
01 static void JC(Args _args)
02 {
03
04 AxaptaUserManager axUserManager;
05 UserInfo userInfo;
06 ;
07
08 userInfo = xUserInfo::find(false, curuserId());
09
10 axUserManager = new AxaptaUserManager();
11
12 if (axUserManager.validatePassword(userInfo.networkAlias , userInfo.NetworkDomain, "4V3rYC0mpl3xPa$$w0rd!!"))
13 {
14 info ("Welcome to the jungle!!!");
15 }
16 else
17 {
18 info ("Intruder");
19 }
20
21}
In the line number 12, the last parameter of the code is a very complex password of the user of the first parameter in the domain specified in the second parameter, return true if the password is correct!
I do not want to insult your intelligence, so I do not profundize on the topic, LOL
Labels:
Ax2009,
AX2012,
AxaptaUserManager,
Dynamics Ax 2012 R3
Tuesday, November 24, 2015
Creating a CSV File from Ax
Hi!
Now I am about to show you how create a CSV file in Ax 2012 R3.
First of all, we need to create an instance of the class CommaTextIo, a Container, and the reference to the #File macro.
01 static void CreateCSV(Args _args)
02 {
03 CommaTextIo file;
04 Container line;
05 InventTable inventTable;
06 #File
07
08 file = new CommaTextIo("c:\\users\\jarizmendi\\aCSVFile.csv", #io_write);
09 if (!file || file.status() != IO_Status::Ok)
10 {
11 throw error("File cannot be opened.");
12 }
13
14 while select * from inventTable
15 {
16 line = [inventTable.ItemId, inventTable.ItemName];
17 file.writeExp(line);
18 }
19 info("It works!!.");
20 }
Then, we need to create the CSV file in a specified directory, and finally, we need to write the data as lines 14 to 18 show.
I hope it helps!!
Now I am about to show you how create a CSV file in Ax 2012 R3.
First of all, we need to create an instance of the class CommaTextIo, a Container, and the reference to the #File macro.
01 static void CreateCSV(Args _args)
02 {
03 CommaTextIo file;
04 Container line;
05 InventTable inventTable;
06 #File
07
08 file = new CommaTextIo("c:\\users\\jarizmendi\\aCSVFile.csv", #io_write);
09 if (!file || file.status() != IO_Status::Ok)
10 {
11 throw error("File cannot be opened.");
12 }
13
14 while select * from inventTable
15 {
16 line = [inventTable.ItemId, inventTable.ItemName];
17 file.writeExp(line);
18 }
19 info("It works!!.");
20 }
Then, we need to create the CSV file in a specified directory, and finally, we need to write the data as lines 14 to 18 show.
I hope it helps!!
Labels:
AX2012,
CommaTextIo,
Dynamics Ax 2012 R3,
X++
Friday, November 20, 2015
Updating Inventory Dimensions Group in Ax 2012
Hi!
If you need to change the Inventory Dimension Groups In Ax (StorageDimensionGroup and TrackingDimensionGroup), you could use this.
1 InventTable inventTable;
2 EcoResStorageDimensionGroup ecoResStorageDimensionGroup;
3 EcoResTrackingDimensionGroup ecoResTrackingDimensionGroup;
4 ;
5 inventTable = InventTable::find("anArticle");
6 ecoResStorageDimensionGroup = ecoResStorageDimensionGroup::findByDimensionGroupName("anotherGroup");
7 ecoResTrackingDimensionGroup = ecoResTrackingDimensionGroup::findByDimensionGroupName("anotherGroup");
8
9 InventTableInventoryDimensionGroups::updateDimensionGroupsForItem(
10 curext()
11 , inventTable.ItemId
12 , ecoResStorageDimensionGroup.RecId
13 , ecoResTrackingDimensionGroup.RecId
14 , inventTable.Product);
15 }
Line 1 to 4 declarations, line 5 to 7 finding the ItemId named "AnArticle" and the Storage Dimension Group and the Tracking Dimension Group, they both named "anotherGroup".
Line 9 performs the updateDimensionGroupsForItem of the class InventTableInventoryDimensionGroups.
Important!. There must not be physical movementsor financial movements pending for this item.
If you need to change the Inventory Dimension Groups In Ax (StorageDimensionGroup and TrackingDimensionGroup), you could use this.
1 InventTable inventTable;
2 EcoResStorageDimensionGroup ecoResStorageDimensionGroup;
3 EcoResTrackingDimensionGroup ecoResTrackingDimensionGroup;
4 ;
5 inventTable = InventTable::find("anArticle");
6 ecoResStorageDimensionGroup = ecoResStorageDimensionGroup::findByDimensionGroupName("anotherGroup");
7 ecoResTrackingDimensionGroup = ecoResTrackingDimensionGroup::findByDimensionGroupName("anotherGroup");
8
9 InventTableInventoryDimensionGroups::updateDimensionGroupsForItem(
10 curext()
11 , inventTable.ItemId
12 , ecoResStorageDimensionGroup.RecId
13 , ecoResTrackingDimensionGroup.RecId
14 , inventTable.Product);
15 }
Line 1 to 4 declarations, line 5 to 7 finding the ItemId named "AnArticle" and the Storage Dimension Group and the Tracking Dimension Group, they both named "anotherGroup".
Line 9 performs the updateDimensionGroupsForItem of the class InventTableInventoryDimensionGroups.
Important!. There must not be physical movementsor financial movements pending for this item.
Labels:
Dynamics Ax 2012 R3,
InventTableInventoryDimensionGroups,
Storage,
StorageDimensionGroup,
Tracking.,
TrackingDimensionGroup,
X++
Subscribe to:
Posts (Atom)



