Using RecordSortedList in Dynamics AX 2012

Dynamics AX 2012 has a nice class called RecordSortedList, which can be used to create a list of records from a database table. It can be useful when you need to pass a list of records into a method, or return a list of records from a method.

I honestly haven’t used it that often, but I had a case today where I thought it would be perfect. I had a method that currently returns a single record from a table, but that needed to be changed to return a short list of records.

I wrote some code to insert records into the list, then another bit to loop through the list and do something with the records in it. I was puzzled that, while I was definitely inserting multiple records into the list, I was only getting a single record back out. After some trial and error, I discovered that the methods to retrieve records from the list don’t really work right if you fail to explicitly set a sort order on the list. I wasn’t really concerned with sort order, so I didn’t bother setting one at first. Once I set a sort order, everything worked fine.

If you want to see this quirk for yourself, run the test job below with and without the sortOrder() call. As far as I can tell, this isn’t actually documented anywhere, so I thought I’d write up this blog post, as a reminder for myself, and as a resource for anyone else who happens to stumble across this little quirk.

// https://gist.github.com/andyhuey/84495f8a3480d2df31f9
static void AjhTestRSL(Args _args)
{
    CustTable custTable;
    RecordSortedList myList = new RecordSortedList(tableNum(CustTable));
    boolean moreRecs;

    myList.sortOrder(fieldNum(CustTable, AccountNum));

    // create a list
    while select firstOnly10 * from custTable
    {
        myList.ins(custTable);
    }

    // step through the list
    moreRecs = myList.first(custTable);
    while (moreRecs)
    {
        info(custTable.AccountNum);
        moreRecs = myList.next(custTable);
    }
}

Windows 10

I just installed the Windows 10 preview on my laptop, in a virtual machine running under VirtualBox. I’m sure I could have done this without instructions, as there wasn’t anything tricky about it, but I used the instructions found here.

I’m trying VirtualBox for the first time. Previously, before I wiped the laptop and re-installed everything, I was using Hyper-V. I wasn’t entirely happy with it, though, as I’d had some networking issues, both on the host and on the VMs. So I decided to give VirtualBox a try. I’d rather use VMWare, since that’s what I use at work, but a new license for that is $250, and VirtualBox is free.

I don’t have much to say about Windows 10 yet. I’ll try to play around with it a bit tomorrow, or over the weekend. I do think Microsoft is back on the right track with Windows, based on the new Start menu, and some of the other enhancements they’ve made.

Ditto on VirtualBox. So far, it works fine, and hasn’t screwed up my networking, so that’s cool.

more comics

Well, I had hoped that I’d feel better this weekend, and would be able to get out and enjoy the nice weather, but I’m still a bit sick. I’m on antibiotics now, so I’m hopeful that I’ll be over this thing by next weekend. Meanwhile, I think this is going to be another weekend of reading comics, watching TV, drinking herbal tea, and making lentil soup.

I finished all the single issues of Usagi Yojimbo I had, so I’ve read through to issue #125 now. I will likely continue reading the series in trade paperback form from here on. And I may be buying those collections via Dark Horse’s digital store, rather than in physical form. The digital collections are $10 each, which is a little cheaper than the physical books. I also want to pick up 47 Ronin and Yokai.

I’m not sure what I want to read to while away the rest of this afternoon, but I think maybe it’ll be Classic Usagi Yojimbo, which was probably the first thing I bought via the Dark Horse digital store, a few years ago. I realized recently that I’d bought quite a few things from the Dark Horse digital store, but hadn’t actually read any of them yet!

comics

I’ve been sick for the last two weeks, so I’ve had a chance to catch up on some comic book reading this weekend and last. I finished Essential Avengers, Vol. 3 last weekend, and started Nick Fury, Agent of S.H.I.E.L.D., collecting Jim Steranko’s work on SHIELD. This weekend, I read the beginning of Mark Millar’s run on Fantastic Four and I’m starting into my backlog of Usagi Yojimbo comics.

I had bought the first few Essential Avengers books at half-price at a con several years ago, on a lark. I wanted to read the first couple of volumes just for the sake of reading some classic Lee/Kirby stuff and just general early Marvel oddball stuff. The first volume, indeed, had some classic Lee/Kirby stuff in it. In the second volume, though, the title settled into a pretty mediocre run, with Lee handing off to Roy Thomas, and with some pretty average and less-than-memorable art and stories. I wasn’t really expecting much from the third volume, but the series really picked up some steam here, with Thomas doing some goofy stuff at the beginning, but getting into some interesting stuff near the end. The earlier issues had some great John Buscema art, and later in the volume, we get a few issues each from Gene Colan and Barry Smith. So now, looking at what’s ahead in volumes 4 and 5, I think I’d like to pick them up and read them. I’m not going to buy them real soon, but they’re on my wish list, once I catch up on some of the other stuff in my backlog.

I stopped buying monthly books partway through Mark Millar’s FF run, so I don’t have the whole thing, but I enjoyed the first part of it enough to order a copy of the second trade, Fantastic Four: The Masters of Doom, so I can complete the run. I’m not quite sure If I’m going to like how it ends, since this trade has gotten some mixed reviews, to say the least. But I’ll give it a chance.

Well, I’ve got a whole Sunday to kill, drinking herbal tea and reading comics, so it’s back to Usagi for me!

Swatch Sistem51

I just got a new “Sistem51” watch from Swatch. I got interested in this watch after reading a review of it on Hodinkee. I like the idea of a reliable, automatic, watch for a reasonable price. (The other automatic I have is my Dad’s old Rolex. And old Rolexes don’t really count as terribly reliable or reasonably priced. Though in my case, it didn’t cost me anything, and it’s been OK since having it serviced a few years back. But I digress.)

I’ve had two other Swatches, one of which I bought in the early 90s and the other in 2003 or thereabouts. Both were their cheapest plastic watches, which generally go for around $60 (or did when I last checked). I’ve replaced the watch bands on both of them multiple times, but they’ve both kept ticking since I bought them, no problem. I just threw out the older one, since the part of the watch that the band attaches to had broken in such a way that I couldn’t attach a new band. (The watch still kept perfect time.) And the newer watch is still working fine.

The Sistem51 is an interesting concept. You can read more about it at the Swatch site or the Hodinkee article, but, basically, it’s a machine-assembled, sealed, automatic watch. So, in theory, it should just keep running for quite some time without any trouble.

The strap on it is leather, but the buckle is plastic, so I have a feeling that I’ll probably need to replace that at some point. But the band itself isn’t going to snap like the plastic ones do. I plan on using this watch as my regular, day-to-day, watch. I’m hoping it will last at least five years before needing a new strap. Maybe when something does eventually go wrong with it, I’ll remember this blog post and write an update.

Windows 8 fresh install

After last week’s successful, but not terribly useful, Windows refresh, I decided to go ahead and just reformat my ThinkPad and do a fresh install. I had to step back to Windows 8, since I have no Windows 8.1 install media, and no 8.1 product key. So that’s a bit of a pain, but I can live with it.

So far, I’ve successfully installed Windows 8, then installed all pending Windows updates, and now I’m doing the 8.1 upgrade from the Windows Store. I started the whole process at around 10 am, and it’s just about 2 pm now, so it’s taken quite a while. But I did run out for a haircut during the Windows 8 install, and out for a walk while the updates were downloading/installing, so I could be further along if I’d stayed home.

Once the 8.1 upgrade is done, I’ll have a bunch of software to install. But I’ll finally have a clean laptop, free of all the Lenovo cruft that got pulled along when I first upgraded from Win 7 to 8. And free of various past Visual Studio installs and other dev tool installs that weren’t easily removed.

NYC trip today – The Met and MoMA

I took a trip into NYC today to visit the Met and MoMA. It worked out pretty well. I got to the Met right around 10am, just after they opened. It wasn’t crowded at all, so I had a nice time casually strolling around and enjoying a nice quiet Sunday visit. I went to MoMA after lunch, and spent a little time there, but not too long. It was a lot more crowded at MoMA, but still manageable. And I finally managed to visit the Monet water lily room, which I blogged about back in June. I got caught up in some Brazilian street festival while walking back to the train station, but managed to extricate myself and get to my train in one piece. So, all in all, a good Sunday in NYC.

Windows 8.1 refresh shenanigans

Yesterday, I decided I wanted to do a system refresh on my Windows 8.1 laptop. This machine is a Lenovo ThinkPad that originally shipped with Windows 7. I’ve since upgraded it to 8 and 8.1. I bought the Windows 8 upgrade online from Microsoft, so I have no install media. And of course I have no install media for 8.1. This leaves me in an awkward position, where I can’t do a normal refresh, as I have a Windows 8 product key, but no media for either 8 or 8.1. This is a pretty well-documented problem, and I think it really reflects poorly on Microsoft that they’ve done nothing to address it.

There are various (slightly Rube Goldberg style) workarounds, none of which worked out for me. The one thing that did work is the solution documented here, using the “recimg” command to create a restore image on my hard drive, which can then be used for the refresh. What that article didn’t make clear, though, is that the image you create that way has all your installed programs in it. That’s clear from this support document, but I didn’t find that one until today.

So, basically, I spent three hours creating a restore image that contained all the installed apps that I wanted to get rid of via the system refresh! Then I ran the refresh, and wound up with a Windows install that was nearly identical to the one I started with. Oh well. I guess the only way to clean things up would be to do a full format and re-install. But, again, since I have no 8.1 install media, I’m not sure I could even do that. It’s enough to drive a guy straight to Ubuntu. (Which probably works pretty well on a ThinkPad. Hmm.)

The main motivation for wanting to do the refresh was that I wanted a nice clean machine for the fall, since I will probably be taking a class via Coursera, and I wanted a good fast machine to work on. Well, I can still mess around with it some more and see what I can do with it.