How to extend your editor in Axapta

The editor in Axapta is as easy to extend as the rest environment. If you check the class EditorScripts, you see a list of methods which is standard. In this example we add a little script which marks your inputed extra code. We always mark all added or changed code, to make it easier to see afterwards what’s added and what’s standard. By doing this it is also makes it very easy to search for all code related to a certain project. This code is an example of what we all use several times a day.

It get’s it’s data from the standard user forms. Here we use the email field to store and get companyname and user-initial from, but you could extend this even more if you like.

To use it, add below code to you EditorScripts class in your environment. Go to Tools, Options and input your initial in the EMail field. Switch to the Developing tab and select a project plus click the save button. Mark a few lines of code in any editor window, right click and select “Scripts” from the option menu. Right under there this script should show with the name FOBeginEnd. When you click on the name, below code fill in the comments you see here, before and after your marked lines.

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
// START 070307 FourOne/HL (FO_EditorAddOns4)
// -- Description:
void FOBeginEnd(Editor e)
{
    int startLine = e.selectionStartLine();
    int endLine   = e.selectionEndLine();
    str             sToday = substr(date2str(today(),
                                321,2,0,2,0,4),3,6);
    str             sCompanySlashUserId, sProject;
 
    str getNameFromEmailField()
    {
        SysUserInfo     sys;
        ;
        select * from sys 
           where sys.id == curuserid();
        return sys.Email;
    }
 
    str getCurrentProject()
    {
        UserInfo        userInfo;
        ;
        select * from userInfo 
           where userInfo.id == curuserid();
        return userinfo.startupProject;
    }
    ;
 
    sCompanySlashUserId = getNameFromEmailField();
    sProject = getCurrentProject();
    e.unmark();
    e.gotoLine(startline);
    e.gotoCol(1);
    e.insertLines("// START " + sToday + " " +
                                sCompanySlashUserId + 
                                " (" + sProject + ")\n" +
                  "// -- Description: \n");
    e.gotoLine(endline+2);
    e.gotoCol(1);
    e.insertLines("// END "   + sToday + " " +
                                sCompanySlashUserId + 
                              " (" + sProject + ")\n");
}
// END 070307 FourOne/HL (FO_EditorAddOns4)

Last 5 posts in Axapta 3.0

3 thoughts on “How to extend your editor in Axapta

Leave a Reply

Your email address will not be published. Required fields are marked *