Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

What's "Onchange", "Onsave" and "Onload" in CRM ?

Posted on by 100

Hi there,

What's "Onchange", "Onsave" and "Onload" in CRM ?

Can you give me an example?

 

 

Thanks

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: What's "Onchange", "Onsave" and "Onload" in CRM ?

    What's "Onchange", "Onsave" and "Onload" in CRM => These are events which get triggered against a control when the page is loaded on the client side.

    is it possible to make certain fields required using the OnSave event and if so where could I find the code? => Yes. You'll need to write a event handler or simply said a javascript function to handle the onSave event when it fires with the logic to make the field you want as required. However, its important to understand when these events get fired as stated in Jason's response before deciding on whether you'd do it in the OnSave or Onchange events.

  • mscrmba Profile Picture
    mscrmba on at
    RE: What's "Onchange", "Onsave" and "Onload" in CRM ?

    Hi Awebio,

    On Load is when a form is loaded in CRM (i.e. the form view for that record is displayed).  This occurs when you open a record, or when you save the record and what is shown on the screen is automatically refreshed.

    On Field Change is when data is manually selected / input into a field.

    On Save is when you have a record open in front of you and you save it.

    These can allow fields to conditionally be displayed/made mandatory/locked/made read only (based on other field values) or data to be defaulted (e.g. today's date), whole sections or tabs to be displayed.

    You can use business rules to do some of these actions e.g. to make fields mandatory (they trigger on-load of the form view and/or on field change, and will show the field as now being 'mandatory' - a red asterix appears on the form view).  Prompts for any missing data then occur if you press 'Save' without having filled in these fields i.e. just before the on save event (you cannot save the record without these fields that are now 'business required' / mandatory).

    The advantage of business rules is that they are configurable (i.e. no coding skills required, and fully supported).  So you get on-load (when the selected record's form loads or refreshes after saving) and on-field-change changes (when a field is updated) in CRM's behaviour without needing to write code.

    However, some things can only be achieved with Jscript e.g. hide/display whole sections or tabs (including their tab/section labels).

  • Suggested answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 17,021 on at
    RE: What's "Onchange", "Onsave" and "Onload" in CRM ?

    To make certain fields required, you can use Business required option for attribute..

    You need to go to entity customization and click on fields, then all attributes in selected entity listed, then double click on attribute it will open new window, change field requirement to Business required.

    f1.PNG

    Then this save attribute and publish. when this attribute is on form, CRM will throw error when it is blank.

    This is easy option.

    Another options are

    JavaScript.. you need to add JavaScript code on form onSave and need to check attributes has value or not.

    To add javaScript you need to create javaScript web resource add it to form libraray and add function on form Onsave

    f1.PNG

    When you click on Add (4) then new window will come, need to add JavaScript function name.

    which has your code..

    Another option is Real time workflow or plugin-- for these options needs to write some .net code and need to register code to CRM.

    For validation you need to use plugin or real time workflow.. when there is another source for data.. I mean data will be added to CRM other than CRM user interface.

    Hope this will help..  

  • Awebio Profile Picture
    Awebio 140 on at
    RE: What's "Onchange", "Onsave" and "Onload" in CRM ?

    Jason, is it possible to make certain fields required using the OnSave event and if so where could I find the code?

  • Suggested answer
    jlattimer Profile Picture
    jlattimer 24,558 on at
    Re: What's "Onchange", "Onsave" and "Onload" in CRM ?

    In order to customize CRM further, you can add JavaScript code to certain form events to extended the functionality beyond what comes out of the box.

    These are a few of the events you can tie your custom code into.

    OnChange - the event when a field value changes - ex. you change the account name from 'ABC' to'123'

    OnLoad - the event the happens when the form loads and after the data is populated - ex. when the form opens you check the value of a certain field and pop up a message to the user to remind them to do something

    OnSave - the event just prior to saving the data back to the database - ex. the perform some additional validation on the data before saving and cancel the save if the data does not meet your requirements

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans