Monday, February 28, 2011

Creating a simple Pager user control with ASP.NET and C#

The following is a simple user control that will display a Pager functionality for any type of web page that deals with large amount of data that need to be segmented in pages.

This is part of a larger project and perhaps in the future I will present the finished project, but for now this user control can help us organize our data with a data list.

  1. Create a new web site project in Visual Studio
  2. Add a new Web User control named Pager.
  3. In Source View (Asp.Net) write the following code
  4. <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Pager.ascx.cs" Inherits="UserControls_Pager" %>
    <p>
    Page
    <asp:Label ID="currentPageLabel" runat="server" />
    of
    <asp:Label ID="howManyPagesLabel" runat="server" />

    <asp:HyperLink ID="previousLink" runat="server">Previous</asp:HyperLink>

    <asp:Repeater ID="pagesRepeater" runat="server">
        <ItemTemplate>
            <asp:HyperLink ID="hyperlink" runat="server" Text='<%#Eval("Page") %>' NavigateUrl='<%#Eval("Url") %>' />
        </ItemTemplate>
    </asp:Repeater>
    <asp:HyperLink ID="nextLink" runat="server">Next</asp:HyperLink>
    </p>

Table methods using ValidateWrite() ValidateDelete() initValue() ModifiedField() - Microsoft Dynamics AX 2009

Table methods using ValidateWrite() ValidateDelete() initValue() ModifiedField()

initValue()This method file while creating new record to initialize a value, here I am assigning user id to the userID field.

public void initValue()
{
super();
this.UserId = curuserid();
}

Sunday, February 27, 2011

Schedule a Windows Task to call an ASP.NET web page - ASP.NET - VB.NET, Windows Task Scheduler

The following is how you can schedule a windows task that can call an ASP.NET web page. Usually we want to schedule task from Windows. I have seen lots of questions regarding this in the past.

The cool thing about Windows task is that you can execute custom jobs to be executed in the server without the need of a user to be logged in.

The following code can be used to call ASPX web pages to run a specific job that needs to execute some sort of logic. The script is written in VB.NET, but the web page can be written with C# as the vbscript only is used to create the call from the server to the page.

The steps are as follow:

Friday, February 25, 2011

Get Employee email with X++ - Microsoft Dynamics AX

The new way Microsoft Dynamics AX handles employee records is very different from the prior versions. For example, in AX 3.0 or 4.0 the employee table will have an email for a specific record, so you could just do something like this to retrieve an employee email:

EmplTable::find(emplId).email;

I needed to get the Employee ID for a custom functionality that sends a sales status confirmation email to a contact with copy to the employee that is handling that Sales Order.




In Microsot Dynamics AX 2009, however, the employee's information is handled diferently. For example, the Employee contact information is stored in a table called DirECommunicationAddress, and the Employee's address is stored in the Address table.

Wednesday, February 23, 2011

SalesCreateQuotation - Always set an Address when creating a new Sales Quotation - Microsoft Dynamics AX 2009

I was faced with a very weird problem today at work. When a user goes to Sales Quotations and clicks the New button, he/she gets the SalesCreateQuotation form (Show below). In our implementation of this form, a contact is required. So, the user always has to choose a contact that is related to the business relationship that it is being quoted.

Now, the issue is that when users create a contact, they only set basic data such as email, and more often than not, the address fields are left blank.

Save an Microsoft Dynamics AX 2009 report to a PDF file (Second Part) - Save the file to a network location

In this part of the article we'll continue to build our functionality to save an Axapta report to a PDF format, then save this file to a network location, and then send it as an attachment in outlook.

The firt part of this series in here http://axwonders.blogspot.com/2011/02/save-microsoft-dynamics-ax-2009-report.html

In the prior article I created a job to save an Axapta report to PDF into a local drive ... C:\. In this article, the code from the last article is integrated within the Run() method of a class I created called SalesConfirmReportEmail.

The SalesConfirmReportEmail class gets executed when a a user wants to send and post an Order Acknowledgement on a Sales Order. I will not discuss how the code works from the moment the user clicks ok in the SalesEditLines form, but I will point out the path that the code follows:

So, the user opens the Sales Order form, finds a record, goes to Posting > Acknowledgement , does whatever he/she needs to do and clicks OK.

In my implementation, the user can choose the output for the order confirmation report. This is, in the DocDestination drop down list he/she can choose Preview, Print, and/or Email. In this case the user wants to print the report.

Tuesday, February 22, 2011

Error executing code: The method has been called with an invalid number of parameters. - Microsoft Dynamics AX 2009

When trying to use the COM object to attach a file into Outlook I got the following error message:

Error executing code: The method has been called with an invalid number of parameters.

After setting a breakpoint into the SysInetOutlookMail class AddAttachment method, the code broke in the following line:

_outlookMailAttachments = _outlookMail.Attachments();

Save a Microsoft Dynamics AX 2009 report to a PDF file (First Part)

The following code saves an Axapta report to a PDF file. This is the first article of 3. The next article will show how to save the file into a network share and pass a Sales Order dynamically, and the last part will be about attaching the PDF to an Outlook instance and create a dynamic subject. So, the titles of the three articles will be the same foe exception of the text in parenthesis.

In my case, I'm having a lot of problems saving the file to a network file and then to attach it to Outlook. The code below saves the report to a local palce in your computer.

static void Job10(Args _args)
{
   custConfirmJour     custInvoiceJour;
  SalesFormLetter     salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation,  false);
   PrintJobSettings    printJobSettings = new PrintJobSettings();
   Args                args = new Args();
   boolean             prompt = false;
   boolean             printIt = true;
   ;

    printJobSettings.setTarget(PrintMedium::File);
    printJobSettings.format(PrintFormat::PDF);
    printJobSettings.fileName(@'c:\temp\myfile2.pdf');
  
   salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());

   select firstOnly custInvoiceJour
       where custInvoiceJour.salesid == '18-062467';

   args.record(custInvoiceJour);
   args.caller(salesFormLetter);

   new MenuFunction(menuitemoutputstr(SalesConfirmation), MenuItemType::Output).run(args);

}

Monday, February 21, 2011

Data List Control (.NET) - Create a fully dynamic user control that handles URL links and Css Classes - ASP.NET

A few days ago I wrote a post on how to create a fully dynamic Link class in C# that will return a full query string based on what a user is clicking within a page. In the following example I'll present the table design, Stored Procedure, C# class, CSS Class and ASP.NET user control I'm using to

Invoice Verification - Total Line Calculation from PurchParmTableTotals in PurchEditLine - Microsoft Dynamics AX 2009

Today I had to fulfill the following requirement:
  1. When the user clicks "Invoice Verification" from the Purch Order Form, place the follwing in the PurchEditLines Form
    • Invoice Balance
    • SalesTax
    • Line Discount
    • Balance
Usually you can see these values when clicking the Totals button from the PurchEditLines Form object in AX 2009.




When you clicked the Totals button the PurchParmTableTotals Form gets activated and the PurchTotals class gets instantiated. So I needed to basically replicate what this form is doing to present the values we see above in the PurchEditLines form as show below.

Saturday, February 19, 2011

Create a Link (URL) class for ASP.NET and C#

I was faced with a requirement last week to build a dynamic link generator to manage URL's in a site. The project owner did not want to build the URL in the presentation layer as the site has an ecommerce architecture where there are product categories and products department, which include a category in itself.

Of course, if you think about it, every time that the user clicks on a category or department, the site needs to create a dynamic URL like Catalog.aspx?DepartmentID=1". The Query string will be used to retrieve the value of DepartmentId, which in our example is equal to 1.

Thursday, February 17, 2011

In DCOMCnfg "Run application on this computer" is grayed out for my application on two Windows 7 machines, but it works fine on all other machines

I was having a problem sending an email through outlook in one of the dev machines at work this morning. After reading a few articles about the topic, I eneded up going to the Component Services to edit the Outlook Message Attachment Service component.

Went I got to the window (Start > Administrative tools >

Tuesday, February 15, 2011

Create a Custom Error Page in 4 steps - .NET - ASP.NET - C#

Visual Studio gives us the possibility to handle errors by using many different types of error handling functions. However, we know we need to tell the viewer that something went wrong when the application crashes, and for this we need to implement an Error page.

I remember seeing some custom error pages in the past that were implemented by using a class that will be called after an exception was thrown.

It worked well, but the implementation of an error page can be more efficient and faster by doing the following:

Monday, February 14, 2011

Choose to whom send what type of email from Outlook automatically in Microsoft Dynamics AX 2009

Ax 2009 came with many changes regarding addresses and contacts.

(If you want to learn more from it go here http://www.microsoft.com/downloads/en/details.aspx?FamilyID=052e9dda-667b-42bd-bd13-f8c5aa1bc0f0&displaylang=en)

Now the GAB (Global Address Book) allows you to have a centralized repository of contacts (person and/or organizations), these can be used in many different processes such as Business Relations, Leads, Sales Orders, ect.

Because of this, I came up with an idea to setup a place in the contacts table (and form) where the user can choose to whom send what type of email from Outlook automatically.

Monday, February 7, 2011

SysInfoAction Class - Go to a specific record from the Infolog - Microsoft Dynamics AX 2009

Today I had a requirement that would allow a user to go to a ContactPersonLookup form record from an infolog that would be showed when a user wants to send an email to a contac without an email address.

First I needed to get the ContactPersonId based on the contact's PartyID. The following method takes one parameter (PartyId) and goes trough a simple sql query to get the record I need:

Thursday, February 3, 2011

Inventory Verification - Placing values from PurchParmTotals on PurchEditLines Form in AX 2009


Today I had to fulfill the following requirement:
  1. When the user clicks "Invoice Verification" from the Purch Order Form, place the following in the PurchEditLines Form
    • Invoice Balance
    • SalesTax
    • Line Discount
    • Balance
Usually you can see these values when clicking the Totals button from the PurchEditLines Form object in AX 2009.

Wednesday, February 2, 2011

Great post about Logic and Problem - Solving Skills

The following text is taken from the following web site: http://www.eggheadcafe.com/software/aspnet/29604130/c-algorithms--c-puzzles.aspx


Presuming that you are studying programming, a desire to improve your problem-solving skills and understand logic are excellent goals to have in mind. Almost all of programming is problem-solving, and involves the use of logic.

Free C# books (General) -- Free C# Algorithms Book (Amazing!)

General


Algorithms

Initialize Table Value to a Drop Down List in Sales Quotation Edit Lines - Microsoft Dynamics AX 2009

Today I needed to initialize a bunch of values in the Sales Quotation Edit Lines Form in AX 2009. Basically the form (in Designs) has a Tab Page named Parameters. Within this form you can see the following:



My task was to set the Print Confirmation check box enable property set to false and to set the value of the Reason drop down list to "New Sales Order". A best practice for AX 2009 is to create this logic directly in the Form methods or Tables, rather than setting fields through MorphX.

Tuesday, February 1, 2011

Set a Date Value to a Date Filed in AX 2009 with X++

I was faced with a requirement that I needed to set a date value to a custom date Filed in AX 2009 with X++, with the Purch Order Creation Date.

I knew that the following could work:

...
FormControl control;
;
control = element.design().controlName('PurchTable_OrderDate'));
control.Text = DateTimeUtil::ToStr(purchTable_ds.Object(fieldnum(PurchTable, CretationDateTime);
...

However, I wanted to create a solution that would not be so dependant on the Form object as this can bring headaches when upgrading. Therefore, I decided to do it at the data source level as follow:

purchTable_ds.object(fieldnum(PurchTable, OrderDate)).setValue(DateTimeUtil::date(purchTable.createdDateTime));

The above code is far more efficient and it needs to be set either in the Data Source (PurchTable) of the PurchTable form Init() or Active() method.