Thursday, August 14, 2014

Recently I was working on a project where I was calling into a class and I needed to verify the record that was coming in.  Here is how I did it:

public static void main(Args _args)
{
    MyClass                                myClass;
    RefRecId                                bankChequeTableRecId;
    FormDataSource                          formDataSource;
    ;

    myClass= MyClass::construct();
    if (_args != null && _args.dataSet() == tablenum(BankChequeTable) && _args.record().RecId != 0)
    {
        BankChequeTableRecId = _args.record().RecId;
        if (_args.record().IsFormDataSource() == true)
        {
            FormDataSource = _args.record().dataSource();
        }
    }
    if (BankChequeTableRecId != 0)
    {
        myClass.ToggleEditForAvidSync(BankChequeTableRecId);
    }
    if (formDataSource != null)
    {
        FormDataSource.research(true);
    }
}

Basically I am checking
1. _args has something
2. _args.dataSet() - Checking if this args is a BankChequeTable record
3. _args.record().RecId - Making sure there is a record in the args
4. Setting my RecId variable to the recid passed in by args.
5. _args.record().IsFormDataSource() - I want to know if this is a form data source and later one refresh that datasource.

I have needed this a lot so I thought I would post it up!

Friday, July 18, 2014

Add new Financial Dimension backing entity

Under General ledger -> Setup -> Financial dimensions, open the Financial dimensions form.  If you create a new dimension there is a list of 'Use values from'.  These are the backing entities that you can use values from.  I had a project to add something to this list.  

Rather than type everything out, here is the link to a post I found that gives a perfect description of how to accomplish this. 

Thanks!

Wednesday, June 18, 2014

SalesLine and Financial Dimensions

I was working with the SalesLine recently and needed a custom Financial Dimension added.  I found this great blog post that explains exactly how to do it:

http://www.intergen.co.nz/blog/tim-schofield/dates/2011/12/how-to-add-a-financial-dimension-in-ax-2012/


Wednesday, May 14, 2014

AX 2009 Compare form colors

I have been working a bit in AX 2009 lately and have found that the colors when comparing two objects, do not work.  A quick google search turned up this blog post:


Very good explanation of why and how to fix it. 

Thursday, April 3, 2014

Cheque_US printing 2 pages

I have been working with this report for some time now.  The idea here was that we needed the cheque to print at the BOTTOM of the page, which, according to microsoft should be really easy!

http://technet.microsoft.com/en-us/library/gg230993.aspx

Needless to say, the settings on this page didn't work.  If I tried to use the 'Check start position' to place the check on the page where I needed it, it would throw an error saying 'The starting position of the check is too far down the page.'  
The other potential solution was to just make the page longer, but then we got 2 pages printing with the 2nd page being blank!

GRRRRRR!

Finally I started digging and found out that the report has 'SlipTxt' boxes at the TOP and the BOTTOM of the report.  This is so that you can have your check print on either end and still have a stub.


From what I can tell, although the bottom 2 text boxes were 'Invisible' they still took up space and forced the printing of a second page.
Once I removed those, half of the battle was won.

The other thing I had to figure out was why I couldn't use the 'Check start position' on the check setup form to push the check further down the page.  BTW, These settings can be found in Cash and bank management -> Common -> Bank accounts -> Set up -> Check


To allow higher numbers such as 8.75 and such, you need to dig into the code in TWO places.  That's right, two places.  The 'Print test' you see here has it's own class where is the 'Generate payments' in the Payment journal lines has another class

Print Test - Classes\BankPrintTestCheque\getDocLength
Generate Payments - Classes\CustVendCheque\slipTxtLines

You will notice that you see a switch statement in each of them that looks like this:
 switch (_chequeFormType)
    {
        case ChequeFormType::USStyle,
            ChequeFormType::UKStyle,
            ChequeFormType::ESStyle,
            ChequeFormType::MXStyle,
            ChequeFormType::CAStyle,
            ChequeFormType::FRStyle :            
            chequeDocMm = 88.89;          
            break;
...
...

To allow larger numbers, you will need to change the 88.89 to something much lower.  I did mine to 18.89 and that seemed to be good enough to do what I wanted.

Good luck!



Thursday, March 20, 2014

Barcode on a SSRS Report

Recently I was tasked with adding a barcode to the SalesPackingSlip report.  I had never done a barcode before so I wasn't really sure how this would turn out.

To help me out, I used WMSPickingList_OrderPick as an example.

The first thing we want to do here is create some parameters for the CustFormLetterDocument and the corresponding form. You can get to this form by going Accounts receivable -> Setup -> Forms -> Form setup.  We want to add 2 parameters to the Packing slip section.

As you can see I have added two parameters.  One is the 'Bar code setup', which contains the Font, Font size, and other information that will help the report display the bar code the way you want.  The other is just in case the customer would like to not display the barcode on the report.

The next thing we want to do is add some fields to our SalesPackingSlipHeaderTmp.  I picked the Header tmp table because my barcode will be the PackingSlipId which will, of course, be in the header.
Add the following fields:

  BarCode of type BarCodeString
  BarcodeFontName of type FontName
  BarcodeFontSize of type FontSize

I think the BarCodeString field is obvious, but why the other two?  Well, we want to be able to get the information from the BarCode setup.  So, if the customer wants to change the barcode font or size, the report doesn't have to be changed.

Now we need to modify some code.  The SalesPackingSlipDP class is where we will do all these modifications.  First we start by declaring some class level variables:

    BarcodeSetupId                      barcodeSetupId;
    BarcodeSetup                         barcodeSetup;
    Barcode                                 barcode;
    NoYes                                   showBarcode;

As we use these variables, I will explain what they are used for.
First, we are going to create a method to initialize these variables.

private void initBarcode()
{
    showBarcode     = CustFormletterDocument::find().showPackingSlilpIdBarCode;
    barcodeSetupId  = CustFormletterDocument::find().barcodeSetupId;
    barcodeSetup    = BarcodeSetup::find(barcodeSetupId);
    barcode         = BarcodeSetup.barcode();
}

As you can see here, we are getting the two parameters spoken of earlier.  Then we are using that barcodeSetupId parameter to get all the barcodeSetup information.  As you will see later, this will contain our FontSize and FontName.
The next method we want will actually get the text we want and convert it to a barcode.

private BarCodeString barCode()
{
    str barCodeContents = custPackingSlipJour.PackingSlipId;

    if (!barCodeContents)
    {
        return '';
    }

    if (barcodeSetup.validateBarcode(strUpr(barCodeContents)))
    {
        barcode.string(true,strUpr(barCodeContents));
        barcode.encode();
    }
    else
    {
        throw(error(strFmt("@SYS41409", barcode.barcodeType(), strUpr(barCodeContents))));
    }

    if (!barcode)
    {
        return '';
    }

    return barcode.barcodeStr();
}

Here we are checking to see if there is actual text to encode and then using the barcodeSetup to validate that the text we are trying to encode, fits the criteria in the barcodeSetup (such as Maximum/Minimum length). Then we simply return the barcode string.

The rest is pretty easy!  In our ProcessReport method of the DP class, we should call 'this.initBarcode()' and in our setSalesPackingSlipHeaderTmp we should have the following:

if (showBarcode == NoYes::Yes)
{
        salesPackingSlipHeaderTmp.barCode                    = this.barcode();
        salesPackingSlipHeaderTmp.barcodeFontName            = barcodeSetup.fontName;
        salesPackingSlipHeaderTmp.barcodeFontSize            = barcodeSetup.fontSize;
}

This will only add the barcode if the showBarcode box is checked in the parameters.

The only thing left to do is in visual studio.  
Add a new textbox and set it to use the barCode field you added to the HeaderTmp table.
The only tricky part here is using an expression for your FontName and FontSize.

For FontName, simply go in and add the field as an expression.  Very straight forward.
For FontSize, however, you need to do it a little different.  Go into the FontSize and add an expression, except you will need to encapsulate your field in the Cstr() method along with adding + "pt" + at the end.  This will make the 25pt that the report needs.  Here is an example:



That's it.  Not as difficult as I thought it was going to be, however, there were several new concepts that I had to learn.



Re-print a packing slip

The other day I was working on the SalesPackingSlip report and I didn't want to constantly be packing orders to be able to test it.  

If you go to Sales and marketing -> Inquiries -> Journals -> Packing slip you can see all the Packing slip journals and simply Re-print them!

I actually added a barcode to this report and will be explaining that in my next post later today.