Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to set a field that would allow the user to add to the field and save it

Posted on by 2,645

When field A is set to ABC, I need the comments field to say, "You have entered ABC."  Then if the user adds to the "You have entered ABC." like adding, This is a Test.  I need all of this to still show when the record is saved and then refreshed.  Currently it is removing the "This is a test" part. 

How do I keep all the test.  Then when field A doesn't equal "ABC", I need the comments to reset, but then if a user puts something in the comments, I want that to stay as well.

Thank you in advance for your help.

*This post is locked for comments

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to set a field that would allow the user to add to the field and save it

    I thought I did.  I marked one of your responses and Yes/Verified.  Do I have to do something else?

  • gdas Profile Picture
    gdas 50,085 on at
    RE: How to set a field that would allow the user to add to the field and save it

    Please close the thread by verifying answer.

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to set a field that would allow the user to add to the field and save it

    I did have another script that was firing on load that was messing with this new script.  Thank you for your assistance.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to set a field that would allow the user to add to the field and save it

    Might be you have other customization which is clearing the comments  value , to make it sure you can removed the else part of  above code and attach onchange event and try again.

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to set a field that would allow the user to add to the field and save it

    I did use your code and I did use this latest code that you provided.  But, it is still clearing out the added text.  I don't know why as I only have it onChange.

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to set a field that would allow the user to add to the field and save it

    Did you tried with my code which I shared? just attach this function in the fieldA onchange event? it will not call in the onload event so why your  comments  value is clearing ?

    In addition I have added below code with setsubmitmode always. Its should work .

    function FieldAOnChange() {
        Xrm.Page.getAttribute("nhs_generalcomments").setSubmitMode("always");
        Xrm.Page.getAttribute("nhs_fielda").setSubmitMode("always");
        var fieldAVal = Xrm.Page.getAttribute("nhs_fielda").getText();
        if (fieldAVal == "ABC") {
            Xrm.Page.getAttribute("nhs_generalcomments").setValue("You have entered ABC");
        }
        else {
            if (Xrm.Page.getAttribute("nhs_generalcomments").getValue() == "You have entered ABC") {
                Xrm.Page.getAttribute("nhs_generalcomments").setValue(null);
            }
        }
    }


  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to set a field that would allow the user to add to the field and save it

    I have the field set to ABC, and the "You have entered ABC" appears correctly.  However, if I hit enter after the default verbiage in the comments section and put in Test, save the record.  When the record loads again, "Test" is gone.  I need that to stay....so any additional text would need to stay.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to set a field that would allow the user to add to the field and save it

    Try with this - 

    function FieldAOnChange() {   
        var fieldAVal = Xrm.Page.getAttribute("nhs_fielda").getText();
        if (fieldAVal == "ABC") {
            Xrm.Page.getAttribute("nhs_generalcomments").setValue("You have entered ABC");
        }
        else
        {
            if( Xrm.Page.getAttribute("nhs_generalcomments").getValue() =="You have entered ABC")
            {
                Xrm.Page.getAttribute("nhs_generalcomments").setValue(null);
            }
        }
    }
  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to set a field that would allow the user to add to the field and save it

    If user goes to Field A, and selects the option of "ABC", then the comments field should show "You have entered ABC"    This seems to work.

    If the user now goes in the comments fields and adds on to the "You have entered ABC", the added on part will disappear when the form reloads.  I need the added text to stay there.

    If the user doesn't select "ABC" form Field A, I need the comments field to not show "You have entered ABC", but to show whatever else the user has typed in the comments field.

    I hope this makes sense.  Thank you.

  • gdas Profile Picture
    gdas 50,085 on at
    RE: How to set a field that would allow the user to add to the field and save it

    Hi ,

    Just trying to understand your question , you have two field one is FIeldA and Comments. When you enter some value in fieldA to ABC  , you need to set comments field value something like "You need to enter ABC"  that part is clear for me and your code is  correct below -

    var FieldAOnChange = Xrm.Page.getAttribute("nhs_fielda").getText();
    
    if (FieldAOnChange == "ABC")
    
    {
    
    Xrm.Page.getAttribute("nhs_generalcomments").setValue('You have entered ABC');
    
    }

    Now in the else part if you does not entered FieldA value to ABC then what will happen ? Does comments value will clear ?I If yes then you can write the else part like below - 

        else if (FieldAOnChange != "ABC") {
            Xrm.Page.getAttribute("nhs_generalcomments").setValue(null);
        }

    Above requirement is clear for me , Now what you want to add in FieldA ? User should be enter  "ABC " or able to enter different text in the Field A?

    From above I can say that if user enter FieldA value is "ABC" so your current comment field value "You have entered ABC" , what you want that user clear that text"You have entered ABC" and write something else in the comment , let say user putted " this is test" erasing old comment which has  set by onchange? And then you want to show both the text internally ?  like this  (You have entered ABC This is test)?

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans