Skip to main content

Notifications

Dynamics 365 Community / Forums / Sales forum / Setting up Form Events...
Sales forum
Suggested answer

Setting up Form Events in Form Properties

Posted on by 7
Hi All,

I'm trying to set up an Event for a particular form.  Within the form properties, I'm understanding I need to go to the Event Handler and create a new event. And I also need to go to the Form Libraries and make sure they are set up correctly.  I have tried several times to get this to work correctly but it's failing every time.

Here is my code:
/
function onLoad(executionContext) {
    var formContext = executionContext.getFormContext();  // get form context
    var formType = formContext.ui.getFormType();  // get form type
    // If form type is Create (1), navigate to the desired tab.
    if(formType == 1) {
        formContext.ui.tabs.get(/tab_8/).setFocus();
    } 
    // If form type is Update (2), navigate to another tab.
    else if(formType == 2) {
        formContext.ui.tabs.get(/SUMMARY_TAB/).setFocus();
    }
}
/
My questions:
Do I need to create a whole new library to make this work?
Can I just add this to an existing library?

In the Event Handler, do I need to place the whole code in, or does something else go there?
I'm using the event /OnLoad/ is this accurate?
I'd appreciate any support here! thanks 
Categories:
  • Suggested answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    Setting up Form Events in Form Properties
    Hi partner,
    1.You can add this code to existing library, but creating new library is better.
    2.In the Event Handler, you need add the library that this code existing:
    --then populate function name(You are using is onLoad) and check "pass the execution context as first parameter"
    3.the event /OnLoad/ is correct.
    4.tab name must be correct and you shoud use "" symbol not // in the code:
    Just like this:

    I hope you can verify my answer if it helps you! If you have any questions, please feel free to contact me.
    Regards,
    Leah
  • Community member Profile Picture
    Community member 14 on at
    Setting up Form Events in Form Properties
    Hi,
     
    You will need to have a library that you can edit and put your code in.
     
    In your solution explorer, you can add your existing web resource, then select and edit it in classic.
     
    Classic interface allows you to use the script editor to add your new code.
     
    Then you can go to the solution, open your form and edit it.
     
     
    Add the library in the form,
     
    Add event handler with the function name and make sure to pass the execution context as the parameter.
    Regards,
    Narayan

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,186 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,996 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans