Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Setting up Form Events in Form Properties

(0) ShareShare
ReportReport
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 
  • 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

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans