28 January 2011

Working COM create Doc file

static void Com_word(Args _args)
{
COM wordApplication;
COM wordDocuments;
COM wordDocument;
COM wordRange;
FileName filename;
;
wordApplication = new COM("word.application");
wordApplication.visible(TRUE);
wordDocuments = wordApplication.Documents();
wordDocument = wordDocuments.add();
wordDocument.saveas("D:\\MyDocument.doc");
filename = "D:\\MyDocument.doc";
wordDocument.activate();
wordRange = wordDocument.range(0,0);
wordRange.insertafter("Test me how to create the excel file ");
//wordRange = wordDocument.range(6,19);

wordRange = wordDocument.range(11,26);
wordRange.italic(true);
// if(WINAPI::fileExists(filename))
// {
// WINAPI::deleteFile(filename);
// }
wordDocument.save();
wordDocument.close();
wordApplication.quit();
}

To start up message while opening AX

1. In server Open ->Dynamics AX Clint configuration
give the Message in start up message control
2. In Info Class->startupPost() method-> write a info message

FileOpen window with job select file or Browser window

static void Select_FileOpen(Args _args)
{
/*
This is the demonstration to select the file as a browser window
you can create fileOpen browser window
*/

Dialog dialog;
DialogField dialogField;
Filename filename;
;

dialog = new Dialog("FileOpen");
dialogfield = dialog.addField(typeid(Filenameopen), "File Name");
dialog.run();


if (dialog.run())
{
filename = (dialogfield.value());

}

info(filename);



}

27 January 2011

How to stop the journal posting in GL

Here we can stop the Journal Posting per each chart of Account
select one COA and follow step:
GL->Chart of Accounts -> General Tab -> Administration Group -> Locked in Journal
Check this Box

how to use Resources

To assign sysResource:
Create any button in form->properties->ButtonDisplay: ImageOnly
Property->NormalResource : 104
104 is the Resource ID:::Tools->DevTools->Embeded Resources

To assign User Resource:
Create any button in form->properties->ButtonDisplay: ImageOnly
roperty->NormalImage: select your Image in this area..

25 January 2011

Transfer of modifications from Development to test Environment

Transfer of modifications from Development to test

Close all connections to the files
Shut down all clients
Shut down AOS
Shut down Business connector

Copy the new and modified application files
axXXX.aod
axXXXen-us.ald

Paste files in Destination Environment
axXXX.aod
axXXXen-us.ald

Start the destination environment
Compile the entire AOT
Synchronize the entire database

20 January 2011

compare base enums in a query

Click here
static void Compare_Base_Enums(Args _args)
{
PurchStatus purchstatus;
PurchTable purchTable;
;

purchstatus = Global::enum2int(PurchStatus::Invoiced); // this statement returning baseEnum element value

while select purchTable where purchTable.PurchStatus < enum2int(PurchStatus::Canceled)
{
info(strfmt("%1",purchTable.PurchStatus));
}

}

11 January 2011

Random Generation of number

static void RandomGenerateEg(Args _args)
{
RandomGenerate objRG = new RandomGenerate();
Random objRandom = new Random();
;
//This generates random numbers specified within the given range
//info(int2Str(objRG.randomInt(10,55)));

//This generates random numbers
info(int2Str(objRandom.nextInt()));
}

generate sequence number

static void SequenceEg(Args _args)
{
Sequence objSeq = new Sequence("Test Sequence",8,10,250,1);
print objSeq.currval(); // Displays the current value of the object
while(1)
{
print objSeq.nextval(1);
pause;
}
}

working with TextBuffer class - separate values from string

static void TextBuffer(Args _args)
{
TextBuffer buffer;
str source;
;

source = "I am first,I am second,I am third";
buffer = new TextBuffer();
buffer.setText(source);

while (buffer.nextToken(0, ','))
{
info (buffer.token());
}
}

Working with Dialog

1.Dialog in Job:
static void Dialog_Ex(Args _args)
{
Dialog dlg = new Dialog("Customer");
DialogField df;
Name name;
ABC test;
;
df = dlg.addField(typeid(SysDate),'','');

if(dlg.run())
{
info(df.value());
}
}
2.Dialog in Class
class CreateDialog extends Runbase
{
Dialog dialog1;
DialogGroup dlgGrp;
DialogTabPage dlgDialogTabPage;
DialogField dlgCustAcc;
DialogField dialogCustName;

CustAccount custAccount;
Name custName;

#DEFINE.CurrentVersion(1)
#LOCALMACRO.CurrentList
custAccount,
custName
#ENDMACRO
}
--
protected Object dialog(DialogRunbase dialog, boolean forceOnClient)
{
//Object ret;
;
//ret = super(dialog, forceOnClient);

dialog1 = super();
dialog1.caption("CustDetails");
dialog1.addTabPage("Gen");
dialog1.addGroup("Gen");
dlgCustAcc = dialog1.addFieldValue(typeid(CustAccount),"","Enter Customer");
dialogCustName = dialog1.addFieldValue(typeid(Name),"","custName");
dialog1.addTabPage("Setup");
dlgCustAcc = dialog1.addFieldValue(typeid(CustAccount),"","Enter Customer");
dialog1.addGroup("Setup");
dialogCustName = dialog1.addFieldValue(typeid(Name),"","custName");

return dialog1;
}
--
public container pack()
{
return [#CurrentVersion,#CurrentList,super()];
}
--
public boolean unpack(container packedClass)
{
Integer version = conpeek(packedClass,1);
container base;
boolean ret;
;

switch (version)
{
case #CurrentVersion:
[version,#CurrentList,base] = packedClass;
ret = super(base);
break;
default :
ret = false;
}

return ret;
}
--
public static void main(Args args)
{
CreateDialog cd;
;
cd = new CreateDialog();

if(cd.prompt())
{
cd.run();

}
}

10 January 2011

Working wtih Queries Query_Ex

1.Queries in Jobs
static void Query_Ex(Args _args)
{
Query q;
QueryRun qr;
QueryBuildDataSource qbd;
QueryBuildRange qbr;
SalesTable salesTable;;
q = new Query();
qbd = q.addDataSource(TableNum(salesTable));
qbr = qbd.addRange(FieldNum(salesTable,SalesId));
qbr.value("00078_036");
qr = new QueryRun(q);
while(qr.next())
{
SalesTable = qr.get(TableNum(salesTable));
info(salesTable.CustAccount);
}
}
---------------------------
2.Queries in Reports
In Report -> Fetch Method write the following code for Range

public boolean fetch()
{
boolean ret;

Query q;
QueryRun qr;
QueryBuildDataSource qbd;
QueryBuildRange qbr;
SalesTable salesTable;;

//ret = super();
q = new Query();
qbd = q.addDataSource(TableNum(salesTable));
qbr = qbd.addRange(FieldNum(salesTable,SalesId));
qbr.value("00078_036");//range value
qr = new QueryRun(q);
while(qr.next())
{
SalesTable = qr.get(TableNum(salesTable));
this.send(salesTable);
}
return true;
}
-----
Code for with out range
public boolean fetch()
{
boolean ret;

Query q;
QueryRun qr;
QueryBuildDataSource qbd;
QueryBuildRange qbr;
SalesTable salesTable;;

//ret = super();
q = new Query();
qbd = q.addDataSource(TableNum(salesTable));
qr = new QueryRun(q);
while(qr.next())
{
SalesTable = qr.get(TableNum(salesTable));
this.send(salesTable);
}

return true;
}
-------
Query Run with DS
DataSource added in report SalesTable
Report->Fetch()
public boolean fetch()
{
boolean ret;

QueryRun qr = new QueryRun(this);
;
//ret = super();

while(qr.next())
{
SalesTable = qr.getNo(1);// 1 refer the 1st datasource.
this.send(SalesTable );
}

Add a field in AP-payment journal lines & vendTrans Table it has to update once we done posing Task

Task
Add a field in AP-payment journal lines it has to update once we done posting Click here

i have created a new field in vendtrans table. that field is available in LedgerJournalTrans table also.

Whenever i am doing AccountsPayment->Payment Journal->Post. the record gets stored in the vendtrans table.

(Before posting the record gets stored in the ledgerjournalTrans table and after posting the record is created in vendtrans table.) Now i want to store the value of my newly created field in vendtrans table.(that value gets stored in ledgerjournaltrans, but sfter posting when the same record is created in vendtrans table,but the newly created field value is empty in vendtrans table)
-
Follow these setups.

1. Add the field to the custVendTrans Map
2. Create a new mapping in the VendTrans of custVendTrans Map

CustVendTrans.ProjId == VendTrans.ProjId

3. Class - CustVendVoucher
In the Class declaration add a variable

ProjId updateProjId;///Kranthi

4. Add a new method to CustVendVoucher class

ProjId parmUpdateProjId(ProjId _projId = updateProjId)
{
;
updateProjId = _projId;
return updateProjId;
}

5. In the initCustVendTrans methid of CustVendVoucher class add this line

custVendTrans.ProjId = updateProjId;

6. Class - VendVoucher -> in the newVendVoucherJournal method of vendVoucher class place the below line of code

vendVoucher.parmUpdateProjId(_ledgerJournalTrans.ProjId);

7. Compile the two classes
8.Right click on the CustVendVoucher class and Add-Ins -> "Compile Forward" - which will compile all the classes inherited from this class

07 January 2011

Create form with X++ code ( Run time form )

static void createForm(Args _args)
{
Args args;
Form form;
FormRun formRun;
FormBuildDesign formBuildDesign;
FormBuildDataSource formBuildDataSource;
FormBuildGridControl formBuildGridControl;
FormBuildStringControl formBuildStringControl;
FormBuildStringControl formBuildStringControl2;
FormBuildTabControl formBuildTabControl;
FormBuildTabPageControl formBuildTabPageControl;
FormBuildTabPageControl formBuildTabPageControl2;
FormStringControl formStringControl;
FormGridControl formGridControl;
DictTable dictTable;
int idx;
int idx2;
int idx3;

;

// Create the form header.
form = new Form();

// Add a data source to the form. ID 77 refers to the CustTable.
dictTable = new DictTable(tablenum(CustTable));
formBuildDataSource = form.addDataSource(dictTable.name());
formBuildDataSource.table(dictTable.id());

// Create the form design.
formBuildDesign = form.addDesign("Design");
formBuildDesign.caption("myForm");

// Add tabbed page controls, a grid control, and string controls.
formBuildTabControl =
formBuildDesign.addControl(FormControlType::Tab, "Overview");

formBuildTabPageControl =
formBuildTabControl.addControl(FormControlType::TabPage, "Overview");
formBuildTabPageControl.caption("Overview");

formBuildTabPageControl2 =
formBuildTabControl.addControl(FormControlType::TabPage,"Details");
formBuildTabPageControl2.caption("Details");

formBuildGridControl =
formBuildTabPageControl.addControl(FormControlType::Grid,"Table Grid");
formBuildStringControl =
formBuildTabPageControl2.addControl(FormControlType::String,"Table String");
formBuildStringControl2 =
formBuildTabPageControl2.addControl(FormControlType::String,"Table String");

// Add data fields to controls.
formBuildGridControl.addDataField
(formBuildDataSource.id(),dictTable.fieldName2Id("AccountNum"));
formBuildGridControl.addDataField
(formBuildDataSource.id(),dictTable.fieldName2Id("Phone"));
formBuildGridControl.addDataField
(formBuildDataSource.id(),dictTable.fieldName2Id("Name"));
formBuildGridControl.addDataField
(formBuildDataSource.id(),dictTable.fieldName2Id("Address"));
formBuildStringControl.dataSource(formBuildDataSource.id());
formBuildStringControl.dataField(2);
formBuildStringControl2.dataSource(formBuildDataSource.id());
formBuildStringControl2.dataField(3);

args = new Args();
args.object(form);

// Create the run-time form.
formRun = classfactory.formRunClass(args);

formRun.run();
formRun.detach();

}

Comma separated Values find in string using container

To Separate the values in the string
1.
static void commaSeperateJob(Args _args)
{
str s= "kranthi,kumar,Myname";
int i=1,j;
str s1,s2;
container c;
;
j = strlen(s);
for(i = 1; i <= j ; i++) { if(substr(s,i,1) != ",") s1 += substr(s,i,1); if(i>1 && substr(s,i,1) == "," || i == j)
{
c = c + [s1];
s1 = "";
}
}
conview(c);
pause;
}
2.
---------------------
static void Job(Args _args)
{
container c;
str s;
;
s= "kranthi,kumar,Myname";
c = str2con(s,",");
conview(c);
}
---------------------
3.
static void Cont(Args _args)
{
container c;
str s,s2;
str s3[];
int i,k;
;
s= "one,two,three";

c = str2con(s,",");
k = conlen(c);
// conview(c);
for(i =1; i <= k; i++)
{
s3[i] = conpeek(c,i);
print s3[i];
}
pause;
}

03 January 2011

Box Example

static void Box_Ex(Args _args)
{
Box box;
;
if(box::okCancel("Test",1,"Enter the value","Ok"))
{
throw info("right");
}
else
{
throw error("Enter the correct value");
}
}

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension-...