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

Announcements

News and Announcements icon
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

I have the same question (0)
  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    can you share your code?

  • Jerry P. Profile Picture
    225 on at

    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.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    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

    Hello,

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

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

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

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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 
        }
    }
  • Jerry P. Profile Picture
    225 on at

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

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans