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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to enter a value in a text box by default....

(0) ShareShare
ReportReport
Posted on by 26

I have a situation where I have a text box.  I have created a web resource so that in this text box the user can insert a bullet, dash, or whatever so that it  looks more appealing to them.  I have default text where I need to show when the form loads, but if the person modifies this text in this box, I do not want the form to overwrite it when it reloads again.  I need to have what the user modified to stay and show.  This field isn't dependent on any other field on the form either.

Any help is appreciated.

*This post is locked for comments

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    You might just use a business rule to set the default value:

    www.marksgroup.net/.../dynamics-365-using-business-rules-set-default-values

    But, once you set it, it'll be saved to the database, and I'm not sure if you meant you wanted those default values to only show up on the screen(in which case it will likely require quite a bit of scripting) or if you'd be ok if they were, also, saved

  • USA80 Profile Picture
    26 on at

    I would rather do it scripting since I am not using an other business rules in the form, all done with scripting.  Just can't seem to get it though.  The text that is scripted would show up when it is brand new record on load.  Then/if the user makes changes to it and saves it, then closes the record and opens it back up, I need to show what was saved and what the user modified, not back to the original default scripted text.

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    You can simply add "if" around each default:

    if(Xrm.Page.getAttribute("ATTRIB_NAME").getValue() == null){

     SET DEFAULT HERE

    }

  • USA80 Profile Picture
    26 on at

    I tried this:

    function CreatedonOnLoad()

    {

    var CreatedOn = Xrm.Page.getAttribute("createdon").getValue();

    if (CreatedOn == 'undefined')

    {

    Xrm.Page.getAttribute("nhs_dailycostsharingdaysupplyretail").setValue("<p style='font-size:12pt; font-family: Arial;'>Medicare Formulary as submitted to CMS:</p><ul style='font-size:12pt; font-family: Arial;'><li>Tier 1 = (define)</li><li>Tier 2 = (define)</li><li>Tier 3 = (define)</li><li>Tier 4 = (define)</li><li>Tier 5 = (define)</li></ul>");

    Xrm.Page.getAttribute("nhs_dailycostsharingdaysupplyltc").setValue("<p style='font-size:12pt; font-family: Arial;'>Medicare Formulary as submitted to CMS:</p><ul style='font-size:12pt; font-family: Arial;'><li>Tier 1 = (define)</li><li>Tier 2 = (define)</li><li>Tier 3 = (define)</li><li>Tier 4 = (define)</li><li>Tier 5 = (define)</li></ul>");

    }

    }

    and getting an error "Unable to get property 'getValue; of undefined or null reference

  • ashlega Profile Picture
    34,477 on at

    You probably need to put createdon on the form (can make it hidden, though)

  • USA80 Profile Picture
    26 on at

    That got the error to go away, but not my text box is blank.

  • ashlega Profile Picture
    34,477 on at

    It's not underfined - it's probably just null..

    if (CreatedOn == null )

  • USA80 Profile Picture
    26 on at

    Got it working.  Thank you.  Last issue is that the value was null behind the scenes instead of undefined. Once I fix that in my script it worked like a charm.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans