Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Java script to auto populate a field with specific text

Posted on by 777

Hello, I have a question I am hoping someone can help with. I have a custom activity entity, and when I create a record regarding a particular contact, I'd like to have the "subject" field in my custom entity auto populate with the the initials of the contact followed by "Intake Note"

So for me, the subject field in my custom entity would auto populate with "BT Intake Note" as soon as the record is created. 

Does anyone have a JS code that can do this? 

Thank you! 

*This post is locked for comments

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: Java script to auto populate a field with specific text

    Hi,

    Using real time workflow would be better. You can refer to below picture, but in this case i am using Account and contact as an example

    2388.5.png

    2388.5.png

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Java script to auto populate a field with specific text

    Hi Ben,

      to simplify things (if you need this to happen once a record is created), why don't you make it a real-time workflow?

      (you may need to make "name" field readonly on the form, and, also, make it optional so CRM allows you to save those records without the name field being provided.. The workflow will take care of populating that field) 

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Java script to auto populate a field with specific text

    You can get the contact by using the following code:

    var contact = Xrm.Page.getAttribute("regardingobjectid").getValue()[0].name;

    You will need to build a function to get the initials. You can search online get initials from string. Here is one example:

    gist.github.com/.../7244472d3e1f1ca7ee56

    www.experts-exchange.com/.../Extract-Initials-from-a-Full-Name.html

    After you get the initials:

    Xrm.Page.getAttribute("subject").setValue("BT Intake Note " + initials);

    Hope this helps.

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