Skip to content

ttsBegin

Experiments in Dynamics AX X++ and C# development

  • Sample Page

Tag: SysLastValue

Copy SysLastValue from another user

2016-06-142019-04-09 By Bas

Here’s a little job that helped me resolve issues related to user settings in AX. It copies user settings / usage data from one user to another. Usually when a user is having an issue with a specific form the first thing to do is delete all usage data related to that form. In case you want reproduce that issue yourself you need to copy the settings from that user, so I wrote a little job that does just that.

x++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
static void Util_CopyUserSettings(Args _args)
{
    Dialog          dialog = new Dialog("Copy user settings");
    DialogField     fldFromUser, fldToUser;
    UserId          fromUser, toUser;
    SysLastValue    sysLastValue;
    int             counter = 0;
 
    fldFromUser = dialog.addField(extendedTypeStr(UserId), "From user", "The user to copy settings from");
    fldToUser = dialog.addFieldValue(extendedTypeStr(UserId), curUserId(), "To user", "The user to copy settings to");
 
    dialog.run();
    dialog.wait();
    if (dialog.closedOk())
    {
        fromUser = fldFromUser.value();
        toUser = fldToUser.value();
 
        if (SysUserInfo::find(fromUser).RecId && SysUserInfo::find(toUser).RecId && fromUser != toUser)
        {
            if (Box::yesNoCancel(strFmt("Delete all user settings for %1?", toUser), DialogButton::Cancel) == DialogButton::Yes)
            {
                info(strFmt("Copying user settings from %1 to %2", fromUser, toUser));
                ttsBegin;
 
                delete_from sysLastValue where sysLastValue.userId == toUser;
 
                while select sysLastValue where sysLastValue.userId == fromUser
                {
                    sysLastValue.userId = toUser;
                    sysLastValue.insert();
                    counter++;
                }
 
                ttsCommit;
                info(strFmt("%1 records copied from %2 to %3", counter, fromUser, toUser));
            }
            else
            {
                info("Copy canceled");
            }
        }
        else
        {
            throw error("Invalid / non existing users or same user selected for copy action");
        }
    }
    else
    {
        info("Copy canceled");
    }
}

The output when running the job

Posted in JobsTagged AX 2012, SysLastValue, SysUserInfo, Usage Data, User Settings

Recent Posts

  • Stopping an AOS takes ages due to huge number of temp tables
  • Patching Remote Desktop Connection Manager for CVE-2020-0765
  • Reduce long synchronization times
  • Dynamics AX 2012 RTM on SQL Server 2016
  • Copy SysLastValue from another user

Archives

  • May 2020
  • April 2020
  • June 2016

Categories

  • Deployment
  • Jobs
  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Proudly powered by WordPress | Theme: Heidi