Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Add a Common text as post-fix in a text field.

(0) ShareShare
ReportReport
Posted on by 277

Hi

I want to add a post-fix text "Duplicate" to name field of Opportunity when a new opportunity is created. Thing is I have mapped Fields using 1:N opportunity, which means the name field will be auto populated when the record is created but with name of Parent, but I want to add a Postfix to it, How can I achieve this. Thanks in advance. 

*This post is locked for comments

  • Turbo Forms Profile Picture
    Turbo Forms 277 on at
    RE: Add a Common text as post-fix in a text field.

    Thank you for the quick reply, will give it a try and get back to you.

  • Aric Levin Profile Picture
    Aric Levin 30,188 Moderator on at
    RE: Add a Common text as post-fix in a text field.

    What Alex said...

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Add a Common text as post-fix in a text field.

    Maybe I'll beat Aric to the answer this time.. autonumbering is a different story because you'll need to generate those numbers first of all. I may be easier to move all this functionality into a plugin - there is an example in the post below:

    community.dynamics.com/.../ms-dynamics-crm-generate-unique-auto-number

    Although, it's actually not done right there because it may end up with duplicate numbers. Well, yet another option might be to use one of the existing auto-numbering solutions (you can google them, probably), use them to generate the number, and, then, use a workflow or a plugin to add that number right after the "Duplicate".

    What's important is that the number should be generated after your new record is saved. Otherwise, if two of them are being created at the same time, you will either start getting duplicate numbers, or you'll start getting gaps between the numbers(depending on how you choose to do it if you use onload javascript)

  • Turbo Forms Profile Picture
    Turbo Forms 277 on at
    RE: Add a Common text as post-fix in a text field.

    Hi Aric

    I have used below code by referring your code, Is there a way I can do auto increment numbering next to Duplicate, when ever a new opportunity is added?

    function FormOnLoad() {
    
        if (Xrm.Page.ui.getFormType() == 1 && Xrm.Page.data.entity.attributes.get("new_parentopportunityid").getValue() != null)
        {
            var opplookup = Xrm.Page.data.entity.attributes.get("new_parentopportunityid").getValue();
            var oppname = opplookup[0].name;
    
            Xrm.Page.ui.setFormNotification("This is a Duplicate Opportunity, make required Changes and SAVE it ", "WARNING")
    
            Xrm.Page.getAttribute("name").setValue(oppname + ": Duplicate");
            
        }      
    }


  • Verified answer
    ashlega Profile Picture
    ashlega 34,477 on at
    RE: Add a Common text as post-fix in a text field.

    You will probably need an onload javascript:

    - Check if it's a new form (Use getFormType: msdn.microsoft.com/.../gg327828.aspx )

    - If it is, and if your parent opportunity attribute is filled in, add "duplicate" to the topic like this

    something like this:

    function onLoadOpp()

    {

     if(Xrm.Page.ui.getFormType() == 1 && Xrm.Page.getAttribute("<PARENT_OPP_ATTRUBITE>").getValue() != null)

     {

       getAttribute("topic").setValue(getAttribute("topic").getValue() + " duplicate");

     }

    }

    PS. And, of course, Aric beats me by a few minutes:))

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 Moderator on at
    RE: Add a Common text as post-fix in a text field.

    This should be straight forward with JavaScript.

    Add a function to the onload of your form.

    Check if the form is a new form (Create).

    If it's a new form, get the value from the Name field, append the Duplicate to it, and set the value back to the field.

    var FORM_TYPE_CREATE = 1;

    function onLoad() {

       var formType = Xrm.Page.ui.getFormType();

       if (formType == FORM_TYPE_CREATE)

       {

           var name = Xrm.Page.getAttribute("name").getValue();

           // You should probably check if name has value before the rest of the logic

           name = name + " - Duplicate";

           Xrm.Page.getAttribute("name").setValue(name);

       }

    }

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans