Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Unable to Copy the Selected record from Ribbon Button

(0) ShareShare
ReportReport
Posted on by 340

Hi All,

My requirement is below:

3288.Pic.png

I have a Clone Contact Button. When i select any record and click on that button (Clone Contact) then one record with the same values from selected Record will open.

Then we can edit any field value from that Record and Click on Save.

Now the Problem is how i achive the same.

I have pass Primary Control in JS and pass that primary Control in Ribbon Workbench (CRM Parameter = PrimaryControl) also.

While debugging the JS , i am facing Primary Control is given as NULL.

Can anyone help me to achive the same.

Thanks in Advance.

  • Suggested answer
    NILANKA SEKHAR PAUL Profile Picture
    340 on at
    RE: Unable to Copy the Selected record from Ribbon Button

    Thanks Goutam for this help.

  • Verified answer
    ajyendra Profile Picture
    1,738 on at
    RE: Unable to Copy the Selected record from Ribbon Button

    function run(selectedItems)

    {

       debugger;

       var selectedItem = selectedItems[0];

    var entityFormOptions = {};
    entityFormOptions["entityName"] = "contact";

    // Set default values for the Contact form
    var formParameters = {};
    formParameters["firstname"] = selectedItem.firstname;
    /*formParameters["lastname"] = "Contact";
    formParameters["fullname"] = "Sample Contact";
    formParameters["emailaddress1"] = "contact@adventure-works.com";
    formParameters["jobtitle"] = "Sr. Marketing Manager";
    formParameters["description"] = "Default values for this record were set programmatically.";*/

    Same you can get all data of selected record in selectedItem variable . You can get as I get firstname.

    // Open the form.
    Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
    function (success) {
    console.log(success);
    },
    function (error) {
    console.log(error);
    });

    Hope It helps

  • NILANKA SEKHAR PAUL Profile Picture
    340 on at
    RE: Unable to Copy the Selected record from Ribbon Button

    Hi Goutam,

    Thanks for your answer. I have followed your mentioned steps, but I am facing 1 issue.

    After clicking on the button new form opens but while saving effects goes to the selected record but as per my requirement I wanted to copy the previous record and after saving it will creates a new record.

    Now it is modifying the existing record after saving the newly opened record.

    Please find below my code:

    function run(selectedItems)

    {

       debugger;

       var selectedItem = selectedItems[0];

                       var incidentId = selectedItem.Id;

                       var entityFormOptions = {};

                       entityFormOptions["entityName"] = "contact";

    entityFormOptions["entityId"] = incidentId;

                       entityFormOptions["openInNewWindow"] = true;

    var Parameters ={"new_sourcefield" : incidentid};

    var formParameters = {};

                       Xrm.Navigation.openForm(entityFormOptions,Parameters).then(

    function (success) {

           console.log(success);

       },

       function (error) {

           console.log(error);

       });

    }

    Can you please check that where I am doing the mistake.

    At present it is only create new form but after saving no new record creates and the modified effect implements on the selected record only.

    Thanks in advance.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Unable to Copy the Selected record from Ribbon Button

    Hi Nilanka,

    Follow below reference to get the selected record id  on ribbon button click , once you get selected record Id you can retrieve selected record information using javascript API passing the selected Id in the Odata request parameter. Once you get the information same object you can pass to create cloned record   using API.

    https://ribbonworkbench.uservoice.com/knowledgebase/articles/129783-pass-the-currently-selected-grid-row-s-to-a-custo

    Use CRMRestBuilder to create query for retrieve and create new record.

    www.youtube.com/watch

    Once you create in the onsuccess you can write code to open newly created entity record.

    docs.microsoft.com/.../openform

  • NILANKA SEKHAR PAUL Profile Picture
    340 on at
    RE: Unable to Copy the Selected record from Ribbon Button

    Hi David, Thanks for your reply.

    I dont want to appear the button on grid or sub-grid. Clone Contact button is visible all the time irrespective of record selection. But when i click on any record and select that button record is not being copied.

    Can anyone post any Javascript code for that,

    It will be very helpful for me.

    Thanks.

  • David Jennaway Profile Picture
    14,065 on at
    RE: Unable to Copy the Selected record from Ribbon Button

    It looks like you want the button to appear on a grid or sub-grid. In this scenario, you should use either a FirstSelectedItemId or SelectedControlSelectedItemIds parameter

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 89

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans