web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
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 
I have the same question (0)
  • Community member Profile Picture
    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
  • Suggested answer
    Leah Ju Profile Picture
    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 179 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 110

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 61 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans