20 September 2011

Remove Base Enum elements during run time in Dialog

Hi All

Now you can remove the unwanted elements of your Base Enum during the run time in dialog box.

All you need to do id write this method in your dialog class

public void dialogPostRun(DialogRunbase _dialog)
{
FormRun formRun;
set removeValues;
SysDictEnum dictEnum;
int i,j, enumCount;
;
removeValues = new Set(Types::String);
removeValues.add("None");
removeValues.add("Requested");
removeValues.add("Sent");
acceptedValues = new Map(Types::Integer, Types::Enum);

dictEnum = new SysDictEnum(enumNum(SampleStatus));
enumCount = dictEnum.values();
super(_dialog);
formRun = _dialog.formRun();
formComboBoxControl = formRun.design().controlName(ResetStatus.name());
formComboBoxControl.clear();
for(i = 0; i {
if (removeValues.in(dictEnum.index2Label(i)))
{
continue;
}
formComboBoxControl.add(dictEnum.index2Label(i));
acceptedValues.insert(j, dictEnum.index2Value(i));
j++;
//

}

formComboBoxControl.selection(0);

}

Step 2:

public object dialog()
{
DialogRunbase dialog = super();

;
ResetStatus = dialog.addFieldValue(typeid(SampleStatus),sampleStatus,"SampleStatus");
dialog.allowUpdateOnSelectCtrl(true);
// write the above line in your dialog method.
ResetStatus.displayLength(40);

return dialog;
}


02 September 2011

Job to Create XML File from AX

Now You can create an xml file of the table using the following code

void CreateItemXML()
{

XmlDocument xmlDoc;
XmlElement nodeXml;
XmlElement nodeTable;
XmlElement nodeItem;
XmlElement nodeName;
XmlElement nodeGroup;
XmlElement nodeType;
InventTable inventTable;
#define.filename('e:\\item.xml')//Location of item xml file
;
xmlDoc = XmlDocument::newBlank();
nodeXml = xmlDoc.createElement('xml');
xmlDoc.appendChild(nodeXml);
//Creates xml for all the items which have the ItemGroupId "Television"
while select inventTable where inventTable.ItemGroupId == "Television"
{
nodeTable = xmlDoc.createElement(tablestr(InventTable));

//Add RecId as an attribute
nodeTable.setAttribute(fieldstr(InventTable, RecId),
int642str(inventTable.RecId));
nodeXml.appendChild(nodeTable);

//Add ItemId as a node
nodeItem = xmlDoc.createElement(fieldstr(InventTable, ItemId));
nodeItem.appendChild(xmlDoc.createTextNode(inventTable.ItemId));
nodeTable.appendChild(nodeItem);

//Add Item name as a node
nodeName = xmlDoc.createElement(fieldstr(InventTable, ItemName));
nodeName.appendChild(xmlDoc.createTextNode(inventTable.ItemName));
nodeTable.appendChild(nodeName);

//Add Item group as a node
nodeGroup = xmlDoc.createElement(fieldstr(InventTable, ItemGroupId));
nodeGroup.appendChild(xmlDoc.createTextNode(inventTable.ItemGroupId));
nodeTable.appendChild(nodeGroup);

//Add Item type as a node
nodeType = xmlDoc.createElement(fieldstr(InventTable, ItemType));
nodeType.appendChild(xmlDoc.createTextNode(strfmt("%1",inventTable.ItemType)));
nodeTable.appendChild(nodeType);
}
xmlDoc.save(#filename);
}

29 July 2011

Set progress on operation

we can show the progress of the operation using following code
static void Progress(Args _args)
{
PurchTable _purchTable;
PurchLine _purchLine;
#Macrolib.AviFiles
SysOperationProgress progress = new SysOperationProgress();
;


progress.setCaption("Task");
progress.setAnimation(#AviUpdate);

while select _purchTable join _purchLine where _purchLine.PurchId == _purchTable.PurchId
{
progress.setText("Purchline is getting");//this will show the operation progress
}






}

07 June 2011

Store image in table

Create a table with Container Datatype
IN form take a method getImage() write the following code.
_path = "Image path"
void getImage()
{
Bindata binData = new BinData();
FilePath _path;
ImageStore _ImageStore;

;
_path = "D:\India_flag.gif"; // file path
binData.loadFile(_path);

_ImageStore.ItemImage = binData.getData();
_ImageStore.doInsert();
}
__
take a button and call this method there:
void clicked()
{
super();

element.getImage();
ImageStore_ds.executeQuery();

}

Make Form/Report run automatically when dynamics Ax Starts

When ax starts Kernel Creates an instance of Info class .
Info contains StartupPost() method used to execute the code every time ax starts.

Following example opens InventTable Form automatically when you start ax.

void startupPost()
{
SysSetupFormRun formRun;
Args args = new Args();
;

args.name(formstr(InventTable));
formRun = classfactory::formRunClassOnClient(args);
formRun.init();
formRun.run();
formRun.detach();
}
__

create Purchase order and invoice programmatically using x++ code

Following Job creates the Purchase order from code and post the invoice by making use of PurchFormLetter class.
static void Dev_CreatePO_and_Invoice(Args _args)
{
NumberSeq numberSeq;
Purchtable Purchtable;
PurchLine PurchLine;
PurchFormLetter purchFormLetter;

;

ttsbegin;
numberSeq = NumberSeq::newGetNumFromCode(purchParameters::numRefPurchaseOrderId().NumberSequence,true);

// Initialize Purchase order values
Purchtable.initValue();
Purchtable.PurchId = numberSeq.num();
Purchtable.OrderAccount = '3000';
Purchtable.initFromVendTable();

if (!Purchtable.validateWrite())
{
throw Exception::Error;
}
Purchtable.insert();

// Initialize Purchase Line items
PurchLine.PurchId = Purchtable.PurchId;
PurchLine.ItemId = 'B-R14';
PurchLine.createLine(true, true, true, true, true, false);
ttscommit;

purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(purchtable, // Purchase record Buffer
"Inv_"+purchTable.PurchId, // Invoice Number
systemdateget()); // Transaction date


if (PurchTable::find(purchTable.PurchId).DocumentStatus == DocumentStatus::Invoice)
{
info(strfmt("Posted invoiced journal for purchase order %1",purchTable.PurchId));
}
}
__
Change the documentstatus to packingSlip , if you want to post packing slip.
Enjoy ....Invoicing through Code.

27 May 2011

Multi selected Records getting in grid

// IN form Gird select some records and click button. in button properties MultiSelect: YES
void clicked()
{
CustTable _CustTable;
;

super();

if(CustTable_ds.anyMarked())
{
_CustTable = CustTable_Ds.getFirst(1,false);
while(_CustTable)
{
info(_CustTable.AccountNum);
_CustTable = CustTable_Ds.getNext();

}
}
}

Service class to get the selected record and deleted matching records and refresh the form data source in D365 F&O

 [DataContractAttribute] class ABCUserProfilesBulkDeleteContract {         UserId userId;     [DataMemberAttribute('UserId')]     pu...