Create a button called Clone (as suggested in previous comments), and call an Action from it.
You can use process.js to call the Action:
github.com/.../processjs
You can use a workflow to set the values or use the following code using a plugin (sample is for Case Entity):
The logic is pretty simple. You will need to retrieve your case entity record, and create a new case (which will return your new case id).
Then you need to do a retrieve multiple on all child records, and do a create for each one. See sample below:
Entity sourceCase = service.Retrieve("incident", caseId, new ColumnSet(true));
Guid targetCaseId = CreateCase(sourceCase);
// Retrieve All Child Records of Case
// You will need to do this for each type of child record
EntityCollection childRecords = service.RetrieveMultiple(query);
if (childRecords.Entities.Count > 0)
{
foreach (Entity child in childRecords.Entities)
{
// Similar logic as the Create Case function
CreateChildRecord(child);
}
}
private Guid CreateCase(Entity sourceCase)
{
Entity targetCase = new Entity("incident");
foreach (KeyValuePair<String, Object> attribute in sourceCase.Attributes)
{
string attributeName = attribute.Key;
object attributeValue = attribute.Value;
switch (attributeName.ToLower())
{
case "scag_incidentid":
break;
default:
targetCase[attributeName] = attributeValue;
break;
}
}
try
{
Guid targetCaseId = service.Create(targetCase);
return targetCaseId;
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in the Case function of the plug-in.", ex);
}
}
Hope this helps.