web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

I have the same question (0)
  • Turbo Forms Profile Picture
    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 - MVP Profile Picture
    30,190 Moderator on at
    RE: Add a Common text as post-fix in a text field.

    What Alex said...

  • ashlega Profile Picture
    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
    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
    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 - MVP Profile Picture
    30,190 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

Responsible AI policies

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

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans