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

I have the same question (0)
  • David Jennaway Profile Picture
    14,065 on at

    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

  • NILANKA SEKHAR PAUL Profile Picture
    340 on at

    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.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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

    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
    ajyendra Profile Picture
    1,738 on at

    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

  • Suggested answer
    NILANKA SEKHAR PAUL Profile Picture
    340 on at

    Thanks Goutam for this help.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans