Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Autoset Date on Quick Create Form

(0) ShareShare
ReportReport
Posted on by 225

Hello,

I am trying to set a date field on the Phone Call quick create form but I cannot get the onLoad to work for this as in the web based forms.  My code is

Is there a way I can get the onLoad event to work? It seems the onChange event is working.

Thanks

*This post is locked for comments

  • Jerry P. Profile Picture
    225 on at
    RE: Autoset Date on Quick Create Form

    Yes, that is where it was. I was looking under the event handler on the field properties and not the form properties.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Autoset Date on Quick Create Form

    Hi Jerry ,

    Ideally it  should work with setting new Date(). 

    However I would request you please try with this  -

    function SetTodaysDateOnLoad(executionContext)
    {   
        var todaydate = new Date();
        var today = todaydate.getFullYear() + '/' + (todaydate.getMonth() + 1) + '/' + todaydate.getDate();
        var formContext = executionContext.getFormContext();
        if  (formContext.context.client.getClient() == "Mobile")
        {
            formContext.getAttribute("scheduledend").setValue(today); // You can also try to set directly todaydate
        }
        else
        {
            // Do something here if not mobile client 
        }
    }
  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Autoset Date on Quick Create Form

    Hi,

    open your quick create form via customization, click form properties. Then you can see from there.

  • Jerry P. Profile Picture
    225 on at
    RE: Autoset Date on Quick Create Form

    Hello,

    I did have the additional client check ion there but removed it, How do I add the onLoad event for this?  

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Autoset Date on Quick Create Form

    Hi,

    if  (formContext .context.client.getClient() == "Mobile") <---

    you put the checking , when the client is using Mobile, then only go into your logic, if you wan to achieve in web based, put another checking or else statement.

    Futhermore, register this function in onload event too.

  • Jerry P. Profile Picture
    225 on at
    RE: Autoset Date on Quick Create Form

    I have something like this.

    function SetTodaysDateOnLoad(executionContext)

    {

    var formContext = executionContext.getFormContext();

    if  (formContext .context.client.getClient() == "Mobile")// &&  Xrm.Utility.getGlobalContext.getAttribute("scheduledend").getValue()== null) //commented out for eliminate this piece at this time

    {

    formContext .getAttribute("scheduledend").setValue(new Date()); //Sets today's date

    }

    //formContext .getAttribute("scheduledend").setValue(Date.now());

    }

    The event handler only has the onChange event option.

  • Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Autoset Date on Quick Create Form

    Hi,

    can you share your code?

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans