Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

question with OnLoad and OnChange...

(0) ShareShare
ReportReport
Posted on by 2

Hello,

I have a Java Script to do some things when a change is made to a field.  This is working great.  However, after I save the record, and open that record back up, I have to reclick the field and reselect the option so that the tabs on the screens appear.  I think I have to put something in the OnLoad, but not sure what, any help is appreciated. 

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: question with OnLoad and OnChange...

    Hi,

    I created a situation similar to what i understood from your question i hope it helps.

    Created a custom Feedback entity and there are 2 fields as given below:

    1. Feedback related to specific project(Option Set)
    2. Related Project(lookup field): This field look's up to another entity Project that has only the names of a few projects.

    Scenario: When i change the Feedback related to specific entity as "Yes" it should show the Related Project field.

    Here i first set feedback related to specific project entity as "yes"

    Hence it shows the Related Projects field then i save the form. 

    71302.2.png

    And when i go out of the record and enter the record again even though the field is set to yes it does not show the related project field

    71302.2.png

    Solution

    Code :

    var jS = {}

    jS.displayRelatedField = function () {

    var a = Xrm.Page.getAttribute("cf_feebackrelatedtospecificproject").getValue();

    var b = Xrm.Page.getControl("cf_relatedProject");

    if (a == 1) {

    b.setVisible(true);

    }
    else { b.setVisible(false); }

    }

    Explanation:

    I added this code to trigger on OnLoad 

    So what it will do OnLoad is check whether feedback related to specific project is Set to 1 i.e. "Yes"

    If true then the relatedProject field is set to visible

    This will work even when you renter the record as if checks the field onLoad and sets the visiblity

    Thank You

  • Verified answer
    naZir Profile Picture
    naZir 850 on at
    RE: question with OnLoad and OnChange...

    Check onload fucntion or default set value. you might be doing something. If you are calling any function onChange of some filed. call the same function onload.

    EX:

    Onload I am making  new_text1 field as mandatory. So Onload it will be always manadatory. But here you have to check ur condition also to satisfy your business needs.

    function makingMandateFieldsOnChage()//This same function should be called on load also

    {

    debugger;

    var optionSetValue=Xrm.Page.getAttribute("new_optionset").getText();

    if(optionSetValue=="B")

    {

    Xrm.Page.getAttribute("new_text1").setRequiredLevel("none");

    }

    }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans