Friday, May 14, 2010

Sending Fax from AX

Sending Fax from AX is common requirement.
This can be achieved in following way

Use the Com class wrapper wizard and load the Microsoft Fax Service

MFSFaxDocument MFSFaxDocument ;
;
MFSFaxDocument = new MFSFaxDocument();
MFSFaxDocument .Body('C:\\Matrish.txt');
MFSFaxDocument .Recipients().Add('Faxno','Receiver Name');
MFSFaxDocument .Subject('Test Fax');
MFSFaxDocument .Sender().Name('Sender Name');
MFSFaxDocument .Submit('ServerName');

Adding Find\Filter functionality on Display method

Adding Find\Filter functionality on Display method

Override Context method of Form control which is using display method and provide code for filter. E.g I have done below for PhysicalInvent field of InventOnHandItem form.

void context()
{

int selectedMenu;
real test;
formrun fr;
Args ag;
Itemname strtext;
querybuilddataSource qb1;
queryrun qr;
query q;
PopupMenu menu = new PopupMenu(element.hWnd());
int a = menu.insertItem('Find');
int b = menu.insertItem('Filter');
int c = menu.insertItem('Remove Filter');


selectedMenu = menu.draw();

switch (selectedMenu)
{
case -1:
break;

case a:
ag = new args('SysformSearch');
fr = new formrun(ag);
fr.run();
fr.wait();
strtext = fr.design().controlName('FindEdit').valueStr();
if(strtext)
{
q = inventSum_Ds.query();
qb1 =q.dataSourceTable(tablenum(InventSum));
QB1.addRange(FieldNum(InventSum,PhysicalInvent)).value(SySQuery::value(strtext));
INVENTSUM_DS.query(Q);
INVENTSUM_ds.executeQuery();
}
break;

case b:
InventSum_DS.filter(FieldNum(InventSum,PhysicalInvent),Sysquery::value(InventSum.PhysicalInvent()));
break;

case c :
InventSum_DS.removeFilter();
break;

Default:
break;
}

}

Prevent a form from closing

Override canClose method of that form, and call winAPI::minimizeWindow, when
the form cannot be closed.
This is the sample code, but require new checkBox control (named
"okToClose") with "autoDeclare" property is "Yes":


public boolean canClose()
{
boolean ret;
ret = super();
if (okToClose.value() == NoYes::Yes)
{
ret = true;
}
else
{
ret = false;
WinAPI::minimizeWindow(element.hWnd());
}
return ret;
}

Reserving inventory by code

Reserving inventory by code


static void ReserveQty(Args _args)
{
SalesLine SalesLine = SalesLine::findRecId(35522);
InventDim InventDim = SalesLine.inventDim();
InventUpd_Reservation reservation;
;
reservation = InventUpd_Reservation::newMovement(InventMovement::construct(SalesLine,true,inventDim),-5,true);
reservation.updateNow();

}

Code to add EDT of through X++ code

static void Job19(Args _args)
{
UtilIdElements uie;
XInfo XInfo = new XInfo();
TreeNode TNode;
TreeNode DNode;

str Props =
"PROPERTIES\n" +
" Name #AXUStr35\n" +
" Label #\n" +
" HelpText #\n" +
" FormHelp #\n" +
" ArrayLength #1\n" +
" DisplayLength #Auto\n" +
" ConfigurationKey #\n" +
" ButtonImage #Arrow\n" +
" Extends #\n" +
" DisplayHeight #Auto\n" +
" StringSize #35\n" +
" Adjustment #Left\n" +
" Alignment #Auto\n" +
" ChangeCase #Auto\n" +
"ENDPROPERTIES\n";

select maxof(id) from uie where uie.recordType ==
UtilElementType::ExtendedType && uie.utilLevel == XInfo.currentAOLayer();

uie.id++;
uie.utilLevel = XInfo.currentAOLayer();
uie.recordType = UtilElementType::ExtendedType;
uie.name = "AXUStr35";

uie.insert();
DNode = TreeNode::findNode("Data Dictionary\\Extended Data Types");
DNode.AOTrefresh();

TNode = TreeNode::findNode("Data Dictionary\\Extended Data Types\\AXUStr35");
TNode.sysUtilDelete();

TNode.AOTsetProperties(Props);
TNode.AOTsave();

// pause;


}

Code to add EDT of through X++ code

static void Job19(Args _args)
{
UtilIdElements uie;
XInfo XInfo = new XInfo();
TreeNode TNode;
TreeNode DNode;

str Props =
"PROPERTIES\n" +
" Name #AXUStr35\n" +
" Label #\n" +
" HelpText #\n" +
" FormHelp #\n" +
" ArrayLength #1\n" +
" DisplayLength #Auto\n" +
" ConfigurationKey #\n" +
" ButtonImage #Arrow\n" +
" Extends #\n" +
" DisplayHeight #Auto\n" +
" StringSize #35\n" +
" Adjustment #Left\n" +
" Alignment #Auto\n" +
" ChangeCase #Auto\n" +
"ENDPROPERTIES\n";

select maxof(id) from uie where uie.recordType ==
UtilElementType::ExtendedType && uie.utilLevel == XInfo.currentAOLayer();

uie.id++;
uie.utilLevel = XInfo.currentAOLayer();
uie.recordType = UtilElementType::ExtendedType;
uie.name = "AXUStr35";

uie.insert();
DNode = TreeNode::findNode("Data Dictionary\\Extended Data Types");
DNode.AOTrefresh();

TNode = TreeNode::findNode("Data Dictionary\\Extended Data Types\\AXUStr35");
TNode.sysUtilDelete();

TNode.AOTsetProperties(Props);
TNode.AOTsave();

// pause;


}

Code for Displaying Back Ground Colour on the basis of Record

*******This Code is use for DisPlay Back Ground Colour on the basis of
Record
----------------------------------------------------------------------
(1) ##### this is for decaration in foms's ClasssDeclaration
for the perpose of Colour the record.

public class FormRun extends ObjectRun
{
int principal;
int nonPrincipal ;
}

(2)##### this is for the purpose of initializing colour of that perticular
record. this code is written on Forms's Init().
public void init()
{
principal = winapi::RGB2int(192,192,192);
nonPrincipal = winapi::RGB2int(255,255,255);
super();
}

(3)#### this is written on DataSource.

public void displayOption(Common _record, FormRowDisplayOption _options)
{
;
spnSizesEuivalances = _record;
if(spnsizeGroups::findPrincipal(spnSizesEuivalances.SizeGroups).PrincipalGrp)
_options.backColor(principal);
else
_options.backColor(nonPrincipal);
}

Simple code for getting Onhand of item

Here is simple code for getting onhand inventory of some item on specific inventory dimension.

static void InventOnHand(Args _args)
{
InventDimParm InventDimParm;
InventSum InventSum;
InventDim InventDim;
;
InventDim.inventBatchId = '';
InventDim.InventSizeId = '';
InventDim.InventLocationId = '';
InventDimParm.initFromInventDim(InventDim);
InventSum = InventSum::findSum('',InventDim,inventDimParm);
InventSum.availPhysical();
}