Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Adding code to a created custom page using extensions

(0) ShareShare
ReportReport
Posted on by 2,580

Hi all,

I want to do a customization using extensions. For this, I have created a custom page. I want to add code in this custom page. So do I need to create a codeunit for the code of this custom page since I'm doing it using extensions or can I add the code in the custom page itself ?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Adding code to a created custom page using extensions

    Hi all, 

    thank for your support. Finally i've created a new codeunit with some function subscribed to events near the custom code I wanted to include in standard objects. 
    Extensions do not allow any type of code, not even the recall of custom published events; neither the documentation in the objects can be inserted, nor the code in the triggers: nothing of anything.


    But now I have a problem, I should add an option type in a standard option field of standard table .... and not even this can be done !! what is the right way in this case? I did not find documentation about it.

    thanks so much

  • Verified answer
    Tina Menezes Profile Picture
    Tina Menezes 2,580 on at
    RE: Adding code to a created custom page using extensions

    Hi,

    In this case if you want to add the code within the event function and call this function, you will need to do minor changes to the standard code as inserting code within standard functions using extensions is still not supported. If you want a particular event function you have to raise request to Microsoft.

  • Suggested answer
    Mohamad Barada Profile Picture
    Mohamad Barada 180 on at
    RE: Adding code to a created custom page using extensions

    Before Microsoft raise publisher there you can do the following :

    In place of your yellow script you have to call the published and send the variable needed to be changed as VAR .

    when you create a subscriber linked to the publisher that you have call it  in place of your yellow script the code of your subscriber will be called within the PostGLAcc function. Yes you could keep your script and run it as the old way but the new approach of subscriber will help you when you create extensions to have all your scripts in one place and minor script (only 1 line in this case) inside the regular objects of NAV. It will be also much easier when you upgrade cause you can export your codeunits easily.

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 60,062 Super User 2025 Season 1 on at
    RE: Adding code to a created custom page using extensions

    you have to raise a request to Microsoft add to a publisher there.

    Microsoft will review and add

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Adding code to a created custom page using extensions

    Hi, thank you very much.

    i've created a new codeunit, and in this, new function with publisher that you've find

    0474.event.JPG

    now i've this code from NAV 2013 :

     

    this code,  will be enter in event?

    and what i call it, if don't write any code in standar object with extension ??

  • Suggested answer
    Mohamad Barada Profile Picture
    Mohamad Barada 180 on at
    RE: Adding code to a created custom page using extensions

    For Cudeunit 12 you have already 4 publisher one of them is OnBeforePostGenJnlLine(VAR GenJournalLine : Record "Gen. Journal Line") if you want to run your script before postgenjnlline you can use this publisher and create new event subscriber linked to this publisher:

    Event-Subscriber.PNG

    If this event is not suitable for you have to create new function of type publisher and call it in the place within CodeUnit 12 than you have to create new codeunit and new function of type subscriber and link it to the new publisher created and inside the subscriber function you put your script.

    I don't know if this will help otherwise please share with me where do you want to add your script and what is the script to be added in order to be able to provide the right example.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Adding code to a created custom page using extensions

    Thank you for your reply.

    But i've  a doubt: when to create the extension, and it involves entering the code in codeunit 12, in the PostGLAcc function, if I can not enter the code, how can I call the event? can you make an example?

  • Suggested answer
    Mohamad Barada Profile Picture
    Mohamad Barada 180 on at
    RE: Adding code to a created custom page using extensions

    If you are working on Microsoft Dynamics NAV 2017, It's better to use the subscriber concept. so you create a new codeunit and you create a new function with type event and subtype subscriber and you select the event required from the available publisher.

    Let me know if you need any support to create a subscriber function.

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 60,062 Super User 2025 Season 1 on at
    RE: Adding code to a created custom page using extensions

    it wont work.

    we should not modify code in standard codeunits at all.

    if you need then you have to use publishers provided by Microsoft.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Adding code to a created custom page using extensions


    hello, if I do not modify the existing code in a standard codeunit, but add another code, the extension works? Or is it not possible to add code to the codeunit? In this case, if I wanted to enter the code as you proceed? thank you

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans