MSDyn365FO. How to playback a task recording from X++.

s-l300

Warmup of a VM is an old issue and everyone tries to find a workaround. It is critical for demo VMs that are turned off most of the time and you don’t want to demo a product that is slow as hell.

Well-known workaround is to manually open all the forms you are going to use but it’s boring and time-consuming task. One of the yammer users came up with an idea to use task recording and here is an implementation in its dirtiest way (calling private methods on object without any validation) that is good enough for demo anyway, so feel free to improve this code:

class WarmUpRunnableClass
{
    public static void main(Args _args)
    {
        var currentRecording = SysBPMHelper::LoadLocalizedRecordingFromLCS(80244103); //BpmLineId here.

        Args args = new Args();
        args.name(formstr(SysTaskRecorderPane));

        FormRun formRun = ClassFactory.formRunClass(args);
        formRun.init();
        formRun.run();
        formRun.loadRecording(currentRecording);
        formRun.maintainExistingRecording();
        formRun.playToStep(100000);
        formRun.wait();
    }
}

This runnable class could be executed from URL, so you can add it to Windows Task Scheduler and execute it on the VM start automatically.

80244103 is a task recording id that is hardcoded here for simplicity. Previously I recorded it and saved to BPM. You can improve this code and add some smarties to grab it from BPM using search by keyword or any other logic you like.

For those who think that hardcode is good enough to get this number you need to go to LCS, open BPM and find task recording you want to run. PLID value from URL is a number you need:

PLID.png

 

Advertisements

6 thoughts on “MSDyn365FO. How to playback a task recording from X++.

  1. Dan August 29, 2018 / 5:46 am

    hi. Is it possible to load from file (xml file containing the task recording) ?
    thanks in advence
    /Dan

    • Ievgen Miroshnikov August 29, 2018 / 6:42 am

      If it is possible to do it from UI than it is possible to do it from x++ for sure

  2. Shiqian Tao July 8, 2019 / 8:15 am

    Hi, how can I run multiple TaskRecording using your code? Thank you very much.

      • Shiqian Tao July 9, 2019 / 2:14 am

        Thank you for your reply. I tried to detach(), in the second Recording, it will error: “A new recording cannot start while another recording is in progress”. Thank you.

        Args curArgs = new Args();
        curArgs.name(formstr(SysTaskRecorderPane));
        using (Stream uploadedFile = new FileStream(“1.axtr”, FileMode::Open, FileAccess::Read))
        {
        using (Stream recordingStream = SysTaskRecorderUtil::GetRecordingFromPackage(uploadedFile))
        {
        Recording uploadedRecording = TaskRecorderXmlSerializer::DeserializeRecording(recordingStream);
        FormRun trFormRun = ClassFactory.formRunClass(curArgs);
        trFormRun = ClassFactory.formRunClass(curArgs);
        trFormRun.init();
        trFormRun.run();
        trFormRun.loadRecording(uploadedRecording);
        trFormRun.maintainExistingRecording();
        trFormRun.playToStep(uploadedRecording.UserActions.Count);
        trFormRun.detach();
        }
        }
        using (Stream uploadedFile = new FileStream(“2.axtr”, FileMode::Open, FileAccess::Read))
        {
        using (Stream recordingStream = SysTaskRecorderUtil::GetRecordingFromPackage(uploadedFile))
        {
        Recording uploadedRecording = TaskRecorderXmlSerializer::DeserializeRecording(recordingStream);
        FormRun trFormRun = ClassFactory.formRunClass(curArgs);
        trFormRun = ClassFactory.formRunClass(curArgs);
        trFormRun.init();
        trFormRun.run();
        trFormRun.loadRecording(uploadedRecording);
        trFormRun.maintainExistingRecording(); // error: A new recording cannot start while another recording is in progress
        trFormRun.playToStep(uploadedRecording.UserActions.Count);
        trFormRun.detach();
        }
        }

  3. Shiqian Tao July 11, 2019 / 8:35 am

    Can you show some examples of playing back multiple Task Recording? Thank you very much.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s