Opening web pages from menu items in Dynamics AX

This post will show you how to open a web page from a menu item in the standard Microsoft Dynamics AX client. It includes a brief code sample with a step-by-step explanation of how to set up the menu item. Enterprise Portal is not required for this scenario.

class LaunchWebBrowser
{
URL url;
}

public static void main(Args _args)
{
LaunchWebBrowser launchWebBrowser;
;

if (_args && _args.menuItemType() == MenuItemType::Action)
{
if (_args.parm())
{
launchWebBrowser = LaunchWebBrowser::newLaunchWebBrowser(_args.parm());
launchWebBrowser.run();
}
else
{
error(strFmt("No URL specified in the '%1' MenuItem object's Parameters property.", _args.menuItemName()));
}
}
else
{
error("LaunchWebBrowser class must be invoked using a MenuItem object with ObjectType property = Class.");
}
}

public static launchWebBrowser newLaunchWebBrowser(URL _url)
{
LaunchWebBrowser launchWebBrowser;
;

launchWebBrowser = LaunchWebBrowser::construct();
launchWebBrowser.url(_url);

return launchWebBrowser;
}

public static LaunchWebBrowser construct()
{
;

return new LaunchWebBrowser();
}

public URL url(URL _url = '')
{
;
//Determines whether the specified parameter for the current method has the default value.
if (!prmIsdefault(_url))
{
url = _url;
}

return url;
}

public void run()
{
;

if (url)
{
infolog.urlLookup(url);
}
else
{
error("Cannot launch web browser because no URL has been specified.");
}
} 

Then after create a Action MenuItem with  properties :

Parameter — http://www.Google.com

Object Type — Class

Object — LaunchWebBrowser

Save it & open the MenuItem.

Advertisements

Form Method calling Sequence

This gives the information of method calls in the form level while

  1. Opening the Form.
  2. Creating/Updating/Deleting the record in the Form.
  3. Closing the Form.

Sequence of Methods calls while opening the Form

Form — init ()

Form — Datasource — init ()

Form — run ()  

Form — Datasource — execute Query ()

Form — Datasource — active ()

Sequence of Methods calls while closing the Form

Form — canClose ()

Form — close ()

Sequence of Methods calls while creating the record in the Form

Form — Datasource — create ()

Form — Datasource — initValue ()

Table — initValue ()

Form — Datasource — active ()

Sequence of Method calls while saving the record in the Form

Form — Datasource — ValidateWrite ()

Table — ValidateWrite ()

Form — Datasource — write ()

Table — insert ()       

Sequence of Method calls while deleting the record in the Form

Form — Datasource — validatedelete ()

Table — validatedelete ()

Table — delete ()

Form — Datasource — active ()

Sequence of Methods calls while modifying the fields in the Form

Table — validateField ()

Table — modifiedField ()

Table method calling sequences

When you press CTR+N

inItValue()->

When you change data in a field

validateField()  -> validateFieldValue() ->  ModifiedField() ->  ModifiedFieldValue()

When you close the table after entering some data

validateWrite() – > Insert()  -> aosValidateInsert()

When you open the table which will contain some data

If table will contain 10 records this method is called 10 times

aosValidateRead()

When you Save the Record for the first time

validateWrite() ->Insert() – > aosValidateInsert()

When you modify the record and saving

validateWrite() -> update() – > aosValidateUpdate()

When you delete the record

validateDelete() -> delete() -> aosValidateDelete()

Reference:http://msdaxerp.wordpress.com/2013/02/27/345/

To open SSRS report from code/X++ code to open SSRS Report

Below code opens the Dialog box where we can can specify the Parameters:

static void OpenSSRSFromCode(Args _args)
{
SrsReportRunController controller = new SrsReportRunController();

// establish the report name
controller.parmReportName(ssrsReportStr(ReportName,DesignName));

// suppress the parameter dialog
controller.parmShowDialog(true);

// start the operation
controller.startOperation();
}

____________________________________________

SSRS saving in PDF & Passing the Parameters through X++:

static void SSRSReporttoPDF(Args _args)
{

SrsReportRun srsReportRun;

srsReportRun = new SrsReportRun("ReportName.DesignName");

srsReportRun.init();
srsReportRun.reportCaption("ReportName.DesignName");

//Passing the Parameters through X++
//srsReportRun.reportParameter("ParameterName").value("ParameterValue");

srsReportRun.showDialog(false);

// Print to a file named ReportExample in HTML/PDF format.
srsReportRun.printDestinationSettings().printMediumType(SRSPrintMediumType::File);
srsReportRun.printDestinationSettings().fileFormat(SRSReportFileFormat::PDF);
srsReportRun.printDestinationSettings().overwriteFile(true);
srsReportRun.printDestinationSettings().fileName(@"C:\ReportName.pdf");

if( srsReportRun )
{
srsReportRun.executeReport();
}
} 

OR

SSRS saving in PDF

static void SSRSReporttoPDF(Args _args)
{

SrsReportRunController controller = new SrsReportRunController();
SRSPrintDestinationSettings printSettings;

// set report name
controller.parmReportName(ssrsReportStr(ReportName,DesignName));

// get print settings from contract
printSettings = controller.parmReportContract().parmPrintSettings();

// set print medium
printSettings.printMediumType(SRSPrintMediumType::File);
printSettings.fileFormat(SRSReportFileFormat::PDF);
printSettings.overwriteFile(true);
printSettings.fileName(@"C:\Report.pdf");

// suppress the parameter dialog
controller.parmShowDialog(true);

// start operation
controller.startOperation();
}

_____________________________________

Job to Open/Access Menu Item:

static void JobToOpenMI(Args _args)
{
MenuFunction menuFunction;
;
menuFunction = new MenuFunction(menuitemDisplayStr(CustVendReport), MenuItemType::Display);
menuFunction.create();
menuFunction.run();
}

Passing Multiple Records from one form to another through Args in Dynamics Ax 2012

The Scenario is when I select multiple lines in grid from Form A, those records will be passed to FormB and there FormB will received the all those records and filter it and will show.

Step 1: Make one SampleTable which has three fields named (SIno, name, AddressCity).
Step 2: Make FormA with datasource as SampleTable and drag the datasource fields into the design Grid.
Step 3: Drag one button and override the click method and write the following code.(Make sure property:MultiSelect is Yes)
step 4: Make one Display menuitem of FormB.

void clicked()
{

int recordsCount;
SampleTable _sampleTable;
container con;
Args args;
str multiSelectString;
;

args = new Args();
recordsCount = SampleTable_ds.recordsMarked().lastIndex(); // gets the total records selected
_sampleTable = SampleTable_ds.getFirst(1);

while (_sampleTable)
{
// storing recid of selected field in container
con = conIns(con,1,_sampleTable.RecId);

// converting container to string with comma separated
multiSelectString = con2Str(con,’,’);

_sampleTable = SampleTable_ds.getNext(); // moves to next record
}
// passing string
args.parm(multiSelectString);
// calling menu item
new MenuFunction(menuitemDisplayStr(FormBMenuItem), MenuItemType::Display).run(args);
}

step 5: Make FormB with datasource as same table for which you take for Form A i.e., SampleTable and drag the fields in to the
Grid of design part.
step 7: write the following code in to the init method of FormB.

public void init()
{
container con;
int i;
str multipleRecords;
super();
// getting string value from caller
multipleRecords = element.args().parm();

// string to container
con = str2con(multipleRecords,”,”);

// for sorting
for(i = 1;i<= conLen(con) ;i++)
{
SampleTbl_ds.query().dataSourceTable(Tablenum(SampleTbl)).addRange(fieldNum(SampleTbl,RecId)).value(SysQuery::value(conPeek(con,i)));
}

}

Passing Args from one Form to another Form in dynamics Ax 2012

Args concept in dynamics ax is awesome. one can easily pass arguments from one Form to another Form with very less effort. Here, i am going to demonstrate how to pass Arguments from Form to Form. The Scenario is when I select one grid in Form A, that record will be passed to Form B and there Form B will received the whole record and filter it and will show.

Step 1: Make one SampleTable which has three fields named (SIno, name, AddressCity).
Step 2: Make FormA with datasource as SampleTable and drag the datasource fields into the design Grid.
Step 3: Drag one button and override the click method and write the following code.

void clicked()
{
Args args;
FormRun formRun;
;
super();
args = new args(formstr(FormB)); // sending Args(record) to FormB
args.record(SampleTable);
formrun = classfactory.formrunclass(args);
formrun.init();
formrun.run();
formrun.wait();
formrun.detach();

}

step 4: Make FormB with datasource as same table for which you take for Form A i.e., SampleTable and drag the fields in to the
Grid of design part.
step 5: write the following code in to the init method of FormB.

public void init()
{
SampleTable _sampleTable;
super();
_sampleTable = element.args().record();
SampleTable_ds.query().dataSourceTable(Tablenum(SampleTable)).addRange(fieldNum(SampleTbl,RecId)).
value(SysQuery::value(_sampleTable.Recid));
}