Tuesday, January 31, 2012

Document Handling in AX – setup and Example


Some initial setups for enabling document handling in AX-
On the Tools menu, select Options.
Under Document handling, select Document handling active.
Select Update toolbar line button to highlight the Document handling icon on the toolbar when you select a record with documents references.
Documents are stored in a default document archive directory and before you start creating documents, you must select the location in the Parametersform.
Click Basic > Setup > Document management > Parameters.
In Archive directory, type the path to the archive directory, or use the browse button () to select a folder on your network.
Select the Number sequences tab.
In the Number sequence code list, select the number sequence to use for naming your documents.
The document management system handles several types of documents including letters, worksheets, and simple notes. Before you can create documents of a certain type, the document type must be created in the Document type form. 
By default, all documents are stored in the Archive directory selected on the Parameters form. However you can select alternative folders for the individual document types.
Also by default, all document types are available from all forms, but some document types are only relevant for certain tables, such as, if you only want to create customer letters for records in the Customers form. When you associate a document type with a specific table, it is not possible to create any documents of that type, in other tables.
Create new document type
Click Basic > Setup > Document management > Document types.
Press CTRL+N to create a new document type.
In Type, type a code for the document type.
In Name, type a descriptive name for the document type.
In the Job description list, select the type of document to create.
In the Group list, select a group for the document type.
Now, I would like to explain document handling with an example for sales orders form of DOC type. 
Initially set the parameters for document handling.
Go to – >Basic -> setup -> Document Management – > Parameters form
set the archive diretory path ( where the document has to be stored like c:\AxDocuments). Remember when ever u create document for a record, the document gets stored in the above location specified.
Check – use Active document table checkbox.
In the number sequences tab - select the number sequence you would like to use for the documents.
Then, If you want to enable documents for salestable – Go to – > Basic -> setup -> Document Management – > Active document tables form . Then select the name of the table here as salestable and in enable the always enabled checkBox.
Now when you open the salestable form you can find the document handling enabled on the toolbar for the salestable form. Double click the document handling icon and create a new document for that record by clicking the new button and selecting the Document menuitem button.Now you can create documents for the salestable.Once you create documents the documents will be stored in the archive path selected in the parameters form.
When ever u create a document, it hits docuref and docuvalue tables.
In the docuref,it creates a record with the tableid of the salestable, the record id of the salestable and the dataareaid ..etc..and correspondingly a record gets generated in the docuvalue with all the filenames, extensions,path etc
To view the documents in the salestable from itself, i mean in the gird itself here is the way… 
Open the salestable form, Then , I would like to use icons for every record in the salestable.So i will write a display method at the salestable level.
//BP Deviation Documented
display smmDocIconNum
showDocHandIcon()
{
#macrolib.resource
;
if ((select firstonly docuRef where
docuRef.RefCompanyId == this.DataAreaId && docuRef.RefTableId ==
this.TableId && docuRef.RefRecId == this.RecId).RecId)
{
return #RES_NODE_DOC;
}
return #RES_AM_NEW;
}
Now create a new window control in the gird. Add the datasource as salestable and datamethod as showDocHandIcon.
The main class where all the business logic is written is docuAction Class. Now i am going to use this class to open the documents for the records.
Now please override the Mouseup() method of the window control
public int
mouseUp(int _x, int _y, int _button, boolean _Ctrl, boolean _Shift)
{
int ret;
args args;
docuRef
docuRef;
;
ret =
super(_x, _y, _button, _Ctrl, _Shift);
element.showDocument();  
 // Method at form level
return ret;
}
Now add showDocument() method at form level
void showDocument()
{
args args;
docuref docuref;
;
args = new args();
docuRef =
docuref::find(salesTable.dataAreaId,tablenum(SalesTable),salesTable.RecId,today());
args.record(docuRef);
args.parmEnumType(enumnum(Docucode));
args.parmEnum(Docucode::Open);
docuaction::main(args);
}
NOW YOU CAN VIEW YOUR DOCUMENTS FROM THE GRID ITSELF BY DOUBLE CLICKING THE WINDOW CONTROL. 

ActiveX in Axapta


The Microsoft Axapta Object Server supports Microsoft’s COM (Common Object Model), DCOM (Distributed Common Object Model) and ActiveX controls. This enables Microsoft Axapta to use the advanced flexible COM technology either directly or indirectly using third party applications.

In AX, each ActiveX control will be having a classId. This entry will exaplain you how to use html document ActiveX control in Axapta.

How to add ActiveX control to your form 
  • create form by Name MyActiveXExample
  • MyActiveXExample- > design – > New control -> ActiveX
  • Select html document ActiveX control from the list of activex’s displayed by Ax and name the newActiveX control as HtmlActiveX.
  • Make the Autodeclaration property of the newly created ActiveX control to Yes
  • After that , if you want to display html content in that Activex Control,
  • Add the below code in the init() method of your MyActiveXExample form
public void init()
{
str htmlSource;
COMDispFunction webpreviewWrite;
COMVariant text = new COMVariant();
COM ctrl = new COM();
;
super();
htmlSource = @’ <html><pre><hr color="#99CCFF">
<center>
Search in Google
<FORM method=GET action="
http://www.google.com/search">
<TABLE bgcolor="#FFFFFF"><tr><td>
<A HREF="
http://www.google.com/">
<IMG SRC="
http://www.google.com/logos/Logo_40wht.gif" <br></A>
<INPUT TYPE=text name=q size=31 maxlength=255 value="">
<INPUT TYPE=hidden name=hl value="en">
<INPUT type=submit name=btnG VALUE="Google Search">
</td></tr></TABLE>
</FORM>
</center></pre>
<hr color="#99CCFF"></html>’;
ctrl.attach(HtmlActiveX.interface());
webpreviewWrite = new COMDispFunction(ctrl, ‘write’, COMDispContext::METHOD);
text.bStr(htmlSource);
HtmlActiveX.open("");
webpreviewWrite.call(text);
HtmlActiveX.close();
}
 The above code will allow use to browse through google without opening the web page , becasue i added the html controls and the functionalites to the controls to search in google.

I have mapped the htmlActiveX control to my Com object and i am writing the html string to the comVariant. Open ActiveX control by .open() method.  Finally i am calling my comdispFunction object i.e webpreviewWrite.call(text) to open the content in the Activex. Then i closed my ActiveX control by using .close() method

Wednesday, January 25, 2012

Get AOS server name for current session

The following code obtains the AOS server name for the current session:

static void getServerNameForCurrentSession(Args _args)  
 {  
   sysClientSessions cliSessions;  
   sysServerSessions svrSessions;  
   ;  
   select svrSessions  
     exists join cliSessions  
       where cliSessions.SessionId == sessionID()  
         && cliSessions.ServerID == svrSessions.ServerId;  
   info(substr(svrSessions.AOSId, 1, strfind(svrSessions.AOSId, '@', 1, strlen(svrSessions.AOSId))-1));  
 }  

Create new role center in Dynamics Ax 2009


Compiled from Dynamics Ax Developer help for quick reference.
  1. Open Dynamics Ax enterprise portal (default installation is http://servername/sites/DynamcisAx).
  2. Click on Site Action > Create . Choose Web part page (as most Ax role center using this). Complete the page creation.
  3. Open Ax client > AOT > Web > Web menu item > URLs > New URL.
  4. Specify URL Properties by clicking on the elipsis button. Browse Enterprise portal folder and choose the .aspx page created in the step 2.
    If got error go to here.
  5. Set home page property to YES. (If not the page will not be available to be chosen as user profile role center page).
  6. Right click > Import. This will import the page to AOT under web > web files > page definitions.
  7. Locate the new page definition on step 6. Set the page title properties.
  8. Go to Admin > Setup > User profile. Create a new record. Choose the role center column from drop down.
  9. Click view role center button to test.

Friday, January 20, 2012

Launch AOT forms & Reports without using Classfactory from x++


static void Args_report_Job15(Args _args)
{
    Args    args;
    ReportRun reportRun;
    ;
    args = new Args();
    args.name(reportstr(custtranslist));
    reportRun = new reportRun(args);
    reportRun.init();
    reportRun.run();
}

static void Args_form_Job15(Args _args)
{
    Args    args;
    FormRun formRun;
    ;
    args = new Args();
    args.name(formstr(custtable));
    formRun = new FormRun(args);
    formRun.init();
    formRun.run();
    formRun.detach();
}

Launch MenuItem from x++

you can call the menuitem itself using Menufunction.


Here is an example that should work.
static void Menuitem_job(Args _args)
{
MenuFunction mf;
;
mf = new menufunction(menuitemdisplaystr(CustTable), MenuItemType::Display);
mf.run();
}


Above code will open the CustTable From.

Thursday, January 12, 2012

How to Use a Programmable Section in Reports in Dynamics AX

We can use programmable sections to add any kind of customized information for example : sum of fields in the report . 

To activate a programmable section, activate it explicitly with anelement.execute(Number) statement. The Number must be specified in theControlNumber property for the design section.

For example, I've created a prgrammable section calculating the sum of a column in dynamics ax .
To call this section , I add the method element.execute(1); in the fetch method after calling super() and before returning the result of the fetch

public boolean fetch()
{
    boolean ret;  
    ret = super();
    element.execute(1);
    return ret;
}

How to get GrandTotal using autodesign report

Open Property window of Autodeign node in your report & set "yes" to Grandtotal Property--- this will print the total always!!

Enable UAT database over OneBox DevTest environment using JIT

 Dear Friends, In this Article I will show you how to enable UAT database access for Development machine using just-in-time (JIT). Many time...