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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

JavaScript - Create Form Only

(0) ShareShare
ReportReport
Posted on by 1,799

Hi, 

I'm looking to execute my code only when the form is of type Create i.e. it hasn't been saved yet. Effectively, I want my code to only fire once, when the user is first entering data prior to saving the record. 

var createForm = formContext.ui.getFormType;

    if (createForm == 1) {
    
    // do something
    
    }

I've tried both retrieving the createdon field value and the formtype to serve this end; however, a value isn't returned for either.

If I alert createForm the value returned appears to be:

function() {
    return this.$1P_1.getFormType();
    }

Any ideas how to solve this?

I have the same question (0)
  • Verified answer
    sardar ahmed Profile Picture
    520 on at

    Hi JM,

    You are missing brackets at the end of getFormType();

    formContext.ui.getFormType();

  • Verified answer
    Joana Pinto Profile Picture
    740 on at

    Hi,

    Your code is almost 100% correct. getFormType() is a method, not a property:

    var formType = formContext.ui.getFormType();
    
    if(formType == 1) { //create form
    
        // do something
    }

    Try this and let me know.

    Regards,

    Joana

  • Sabahat Zaman Profile Picture
    10 on at

    I'm doing same but it is not working as it is supposed to do.

     function Form_Type (executionContext)
    {
      var formContext = executionContext.getFormContext();    
       var formType = formContext.ui.getFormType();
        if (formType == 1)
        {
        hideSection();
        communication();
        rankHideSect();
        monthlyDeal();
        capitalCity();
        } 
       else if (formType == 2)
       {
        LockUnlock();
        }
    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 180 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 123

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans