Setting breakpoints from cross reference and search result windows

October 25, 2013 at 21:52
filed under Dynamics AX
Tagged , , , , , ,

This guest post is written by my colleague Kristof Meesens. Thank you Kristof for contributing.

Lately I was in a deep debugging mode and used the cross references to find out some stuff.
The cross reference is a great help, but if you want to set some breakpoints it can take a lot of work.
For example you want to set a breakpoint everywhere where a field will be written.
You use the cross reference from the table/field and filter on the reference ‘write’
If you want to set a breakpoint you have to edit each line and set a breakpoint.

I created a class KrMeeSysBreakpoints that will be used to add breakpoints from a container.

The container must contain a Path, a Line number and a Boolean to enable the breakpoint.
This container will be added to another container that the class will use to loop

public void run()
{
    int             i;
    container       bpCon;
    container       bpConTmp;

    if (bpCons != conNull())
    {
        bpCon = infolog.breakpoint();

        for(i=1; i<=conLen(bpCons); i++)
        {
            bpConTmp = conPeek(bpCons, i);

            path = conPeek(bpConTmp, 1);
            line = conPeek(bpConTmp, 2);
            enabled = conPeek(bpConTmp, 3);

            if (line != 0)
            {
                bpCon += [path];
                bpCon += [line];
                bpCon += [enabled];
            }
        }

        infolog.breakpoint(bpCon);
    }
}

To use this functionality, you can add a button to the form of the cross references.
Adding button to sysAotFind form

void clicked()
{
    xRefReferences  xRefReferencesEdit;
    container       bpCons;
    container       bpCon;

    for (xRefReferencesEdit = getFirstSelection(xRefReferences_ds);
         xRefReferencesEdit;
         xRefReferencesEdit = xRefReferences_ds.getNext())
    {
        bpCon = conNull();
        bpCon += [xRefPaths::findRecId(xRefReferencesEdit.xRefPathRecId).Path];
        bpCon += [xRefReferencesEdit.line];
        bpCon += [true];

        bpcons += [bpCon];
    }

    KrMeeSysBreakpoints::newFromContainer(bpcons).run();
}

You can also call this functionality from de search form
Adding button to xRefReferencesUsedByTypedTree form

void clicked()
{
    FormListItem    selectedItem;
    str             selectedData;
    int             i, pos;
    container       bpCons;
    container       bpCon;

    i = ResultListView.getNextItem(FormListNext::Selected);
    while (i != -1)
    {
        selectedItem = resultListView.getItem(i);
        selectedData = selectedItem.data();

        pos = strFind(selectedData, '\\', 1, strLen(selectedData));
        if (pos > 1)
        {
            bpCon = conNull();
            bpCon += [subStr(selectedData, pos, strLen(selectedData))];
            bpCon += [str2int(selectedData)];
            bpCon += [true];

            bpcons += [bpCon];
        }

        i = ResultListView.getNextItem(FormListNext::Selected,i);
    }

    KrMeeSysBreakpoints::newFromContainer(bpcons).run();
}

An example screenshot from the cross references screen:
Sample in Xref

Download the XPO: SharedProject_KrMeeSetBreakpoints.xpo.

6 comments

RSS / trackback

  1. Philippe

    Very good post! Thx

  2. Tommy Skaue

    That is cool! Thanks for sharing! :-)

  3. Kenny Saelen

    Nice one!

    Going to use it as of today :)

  4. Steven De Ridder

    Very useful code. Nicely done.
    Thx Kristof

  5. Tom Van Dyck

    I just LOVE this one!

  6. Ashlesh

    Nice post. Quite helpful. Thanks for sharing.

respond