Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable based on the pick list value selected in the field and the record is saved. How can this be done using JavaScript.

(0) ShareShare
ReportReport
Posted on by 340

Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable on the form based on the pick list value selected in the field and the record is saved.  How can this be done using JavaScript.

  • Sandy Hello Profile Picture
    340 on at
    RE: Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable based on the pick list value selected in the field and the record is saved. How can this be done using JavaScript.

    The above steps worked well for my requirements.

  • Suggested answer
    cloflyMao Profile Picture
    25,202 on at
    RE: Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable based on the pick list value selected in the field and the record is saved. How can this be done using JavaScript.

    Hi Sandy,

    You could download community solution Workflow Tool to create an on-demand workflow for cloning/copying.

    https://github.com/demianrasko/Dynamics-365-Workflow-Tools/blob/master/docs/Clone Record.md

    Then you can run that workflow directly with web api or client api in custom button COMMAND settings,

    Web API(just take the workflow guid as parameter)

    https://carldesouza.com/calling-a-dynamics-365-workflow-through-javascript/

    Client API

    https://www.inogic.com/blog/2019/05/execute-workflow-using-xrm-webapi-online-execute-method-via-javascript-in-dynamics-365-crm-v9/

    Please mark as verified if the answer is helpful, it would be greatly appreciated. :)
    

    Regards,

    Clofly

  • cloflyMao Profile Picture
    25,202 on at
    RE: Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable based on the pick list value selected in the field and the record is saved. How can this be done using JavaScript.

    Hi Sandy,

    I created a demo with account's Industry optionset field as example:

    pastedimage1566438800646v2.png

    When selected option equals any one item among Account, Brokers or Consulting, then the button will be enabled/displayed.

    and I found that there is no need to listen Save event, our function will be triggered automatically:

    1. When selected option equals Business Services initially, the button is hidden,

    2. When we change it to Consulting and click save, the button will appear.(or appear automatically if auto save enabled)

    Your controlling logic could be below:

    function rule() {
      var flag = true;
      var picklist = ["Accounting", "Brokers", "Consulting"];
      var obj = Xrm.Page.getAttribute("industrycode");
      if (obj != null) {
        if (picklist.indexOf(obj.getText()) > -1) {
            flag = false;
           }
        }
        return flag;
    }

    The appearance controlling code is separate from clone/copy logic, so for the function of button itself,

    you could decide which ways to achieve, 

    by Inogic's solution and integrate button appearance controlling code or

    just adding the function that fetching the current record data with Xrm.Page.getAttribute then excute Xrm.webApi.createRecord to ribbon button COMMAND setting.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/createrecord

    Regards,

    Clofly

  • Sandy Hello Profile Picture
    340 on at
    RE: Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable based on the pick list value selected in the field and the record is saved. How can this be done using JavaScript.

    The above steps worked well thanks. I am looking for copy of record form and carry all the fields on to the new form with few fields set to be blank. Please share your thoughts on this

  • Sandy Hello Profile Picture
    340 on at
    RE: Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable based on the pick list value selected in the field and the record is saved. How can this be done using JavaScript.

    Thanks Clofly Mao for Response. Yes additional button is the ribbon button. The pick list field is Option set field and when the value of the field is "rejected" and the record is saved then the " Copy " button should be enabled on the form. For all other option set values the "Copy" button is disabled.

  • Inogic Profile Picture
    438 on at
    RE: Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable based on the pick list value selected in the field and the record is saved. How can this be done using JavaScript.

    To achieve this you can use our one-click product – Click2Clone.

     

    To find more about it you can click here.

    Thanks!

  • cloflyMao Profile Picture
    25,202 on at
    RE: Clone or Copy of existing record when clicking on additional button added on the form. This new button should be enable based on the pick list value selected in the field and the record is saved. How can this be done using JavaScript.

    Hi Sandy, 

    If your additional button means ribbon button:

    You could work with a feature called Enable Rules in Ribbon Workbench solution, it allows us to add our custom javascript code to control whether display ribbon button.  

    1. After you have added a custom ribbon button, click Add Enable Rule button in COMMANDS setting for the custom button:

    today001.JPG

    2. In ENABLE RULES setting, we add a step called CustomRule (custom javascript code), set Default and InvertResult to True,

    (To see how to work with this setting, please read the article: https://www.magnetismsolutions.com/blog/adammurchison/2017/10/13/how-to-use-enable-rules-in-dynamics-365-with-the-ribbon-workbench)

    then add our own function:

    today002.JPG

    3. Display loigic:

     today003.JPG

    If we return a true value in custom function, the button will not display, in example below, the button will be hidden.

    Those above are how to achieve controlling button enabled/disabled, please add your own logic to control your button.

    In you scenario, was pick list an optionset field? and how would you want to check is saved stauts?

    I'm glad to give more implementation if you could share more details of your requirement. :)

    Regards,

    Clofly

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,274 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,939 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans