cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Default Dates in Model Driven App forms

@HSheild (as ever) provided me with a great solution to inheriting a date from a parent to a child in a sub-form.

 

https://powerusers.microsoft.com/t5/Common-Data-Service-for-Apps/Default-date-and-testing-of-date-lo...

 

I now discover that something on the face of it which is more straightforward than that is...not so straighforward.

 

I am trying to populate some default values:

 

I see that in creating a new field in an entity, I can assign a default value to an Option Set type, but not to any other kind of field type? I want the form to default to "Today" in the case of a date field and a specific item in the case of some lookup fields.

 

I have looked at Calculated Fields =Now() but of course that just sets the field on save, not offers a default.

 

Any ideas?

 

Ged

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Default Dates in Model Driven App forms

@ghdunn 

Please try to Create a new Web Resource to hold the JScript. This JScript Library should contain the following code:

 

// Prefill a Date Field with Todays Date 

function SetToday(date)
{    
var isCreateForm = Xrm.Page.ui.getFormType() == 1;
var dateField = Xrm.Page.getAttribute(date);
    if (isCreateForm)   // Check that this is a new Record
    {        dateField.setValue(new Date()); // Set the Date field to Today
             dateField.setSubmitMode("always");   // Save Disabled Fields
    }
}

 

To install:
1.  Create a Web Resource and add the above script to the Web Resource
2.  Add the Web Resource as a Form library and set the forms OnLoad event to the SetToday Function.
         a.   Customize the form, select FormProperties, Events Tab. 
         b.   Add a Library, Under EventHandlers, Control = Form, Event=OnLoad
         c.   In the function field, type in "SetToday"
         d.   In the box that says "comma separated list of parameters that will be passed to the function" add the Schema Name of the field you wish to default as a parameter.   Schema Name must be in double quotes (ie.  "myfield_schemaname")
Snipaste_2020-02-14_15-24-49.pngSnipaste_2020-02-14_15-23-51.pngSnipaste_2020-02-14_15-23-26.pngSnipaste_2020-02-14_15-25-18.png
Sik

View solution in original post

6 REPLIES 6
Highlighted
Super User II
Super User II

Re: Default Dates in Model Driven App forms

Take a look at Business Rules.
They have Default actions, execute in real-time for the user, and are low/no-code to implement.
Not at a computer, otherwise I'd post some examples. Sorry!
Highlighted
Helper V
Helper V

Re: Default Dates in Model Driven App forms

Thanks @GarethPrisk 

 

I want to populate the values on the opening of the form, not on the closing.  Is that possible with Business Rules?  It seems to me the only condition is a test of a field value, which suggests to me it is on closing?

 

Thanks

 

Ged

Highlighted
Community Support
Community Support

Re: Default Dates in Model Driven App forms

@ghdunn 

Please try to Create a new Web Resource to hold the JScript. This JScript Library should contain the following code:

 

// Prefill a Date Field with Todays Date 

function SetToday(date)
{    
var isCreateForm = Xrm.Page.ui.getFormType() == 1;
var dateField = Xrm.Page.getAttribute(date);
    if (isCreateForm)   // Check that this is a new Record
    {        dateField.setValue(new Date()); // Set the Date field to Today
             dateField.setSubmitMode("always");   // Save Disabled Fields
    }
}

 

To install:
1.  Create a Web Resource and add the above script to the Web Resource
2.  Add the Web Resource as a Form library and set the forms OnLoad event to the SetToday Function.
         a.   Customize the form, select FormProperties, Events Tab. 
         b.   Add a Library, Under EventHandlers, Control = Form, Event=OnLoad
         c.   In the function field, type in "SetToday"
         d.   In the box that says "comma separated list of parameters that will be passed to the function" add the Schema Name of the field you wish to default as a parameter.   Schema Name must be in double quotes (ie.  "myfield_schemaname")
Snipaste_2020-02-14_15-24-49.pngSnipaste_2020-02-14_15-23-51.pngSnipaste_2020-02-14_15-23-26.pngSnipaste_2020-02-14_15-25-18.png
Sik

View solution in original post

Highlighted
Helper V
Helper V

Re: Default Dates in Model Driven App forms

@v-siky-msft @GarethPrisk 

 

Great guys..thank you.  Will have a look at that over the weekend and leave feedback.

 

Ged

Highlighted
Community Support
Community Support

Re: Default Dates in Model Driven App forms

Hi @ghdunn 

 

How about the workaround? Is there any progress?

Sik

Highlighted
Helper V
Helper V

Re: Default Dates in Model Driven App forms

Sik

@v-siky-msft @GarethPrisk 

 

So very sorry guys...just got tied up in something else and will be OOO for a couple of days.  I am sure this will work and will test as soon as I am able. Rest assured, I will leave feedback as soon as I am confident.  Sorry i haven't turned this around as quickly as I planned.

 

Ged

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Users online (5,995)