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

Notifications

Announcements

No record found.

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

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 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans