web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Java Script for cloning records

(0) ShareShare
ReportReport
Posted on by 105

HI, I have a ribbon button that shows when a record is selected. With java script I want this button on click to pull values for the selected record via api and open the quick create form for the entity which will be filled with the values for this record. 

Can anyone help me? How do i approach this?

Thank you. 

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hello,

    You can use Custom action and pass the selected record Guid and return newly created record guid from custom action as output parameter. Then call Custom action from javascript on button click, get the record guid from output parameter and open quick create form with that record guid.

    Please see below blog for more details

    www.inogic.com/.../

  • antc Profile Picture
    2,911 on at

    Although there are many ways to clone and some free solutions that will work here is one method:

    Create javascript action for button and send record id to your custom action as shown here https://www.youtube.com/watch?v=rz4wKV3VCNQ

    Then create a plugin and so new cloned record can be created

                var oppguid = (string)context.InputParameters["OPGuid"];
                
                Entity oppproduct = service.Retrieve("opportunityproduct", Guid.Parse(oppguid), new ColumnSet(true));
    
    
                Guid opportunityID = ((EntityReference)oppproduct["opportunityid"]).Id; 
               
                // Call the method to set the attributes
                Entity clone = oppproduct.Clone();
                clone["eye_assetnumber"] = length   1;
    
    
                // Create new record
                Guid cloneId = service.Create(clone);
                
                context.OutputParameters["OutputArg1"] = "You will be redirected to new Opportunity Product:"   Environment.NewLine   "Asset Number: "   newlength   Environment.NewLine   cloneId.ToString();
            }
        }
        public static class EntitiExtensions
        {
            public static T Clone(this T entity) where T : Entity
            {
                Entity clone = new Entity(entity.LogicalName);
                foreach (KeyValuePair attr in entity.Attributes)
                {
                    if (attr.Key.ToLower() == entity.LogicalName.ToLower()   "id" || attr.Key.ToLower() == "activityid") continue;
                    clone[attr.Key] = attr.Value;
                }
                return clone.ToEntity();
            }
        }
    }

    You can then send user to the new record.

    entityFormOptions["entityName"] = "opportunityproduct";
                entityFormOptions["entityId"] = guidopp ;
                Xrm.Navigation.openForm(entityFormOptions).then(
                    function(success) {
                        console.log(success);
                    },
                    function(error) {
                        console.log(error);
                    });

  • Suggested answer
    sjain14 Profile Picture
    5 on at

    I have edited this Java code and this is working perfect. Try this:

                  <!DOCTYPE html>
                  <html>
                   <head>
                  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
                    <title>Clone</title>
                     <script type="text/javascript" src="">ajax.googleapis.com/.../jquery.min.js"></script>
    
                      <script type="text/javascript">
    
                          function addRow() {
    
                              var myRow = '<tr><td> <input type="text" id="p_new" name="data[]" value="some value" ></td></tr>';
    
                              $("#MyTable tr:last").after(myRow);
    
                          }
    
                      </script>
    
    
                   </script>
    
    
                   </head>
                   <body>
                    <div onclick="addRow()" style="color: Blue; text-decoration: underline;">
    
                          Add row to table
    
                      </div>
                     <table border="1"  id="MyTable">
                          <tr>
    
                          <td id="addinput">
                              <input type="text" id="p_new" name="data[]" value="some value" >
                          </td>
                          </tr>
    
                      </table>
    
                  </body>
                  </html>
    
  • Suggested answer
    Sanket Kumar Profile Picture
    90 on at

    You can create a relationship mapping to achieve this.  It should solve your problem 

    docs.microsoft.com/.../map-entity-fields  or if you can use javascript to fetch the value and open quick create using Xrm.naviagteTo

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 103 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 83

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans