Hi all
I want to copy the logic as we have on product as shown below to my custom entity:
How could I achieve this functionality on my custom entity?
Thank you
Regards,
AW
*This post is locked for comments
Hi all
I want to copy the logic as we have on product as shown below to my custom entity:
How could I achieve this functionality on my custom entity?
Thank you
Regards,
AW
*This post is locked for comments
Hi Aric and Pawel,
I created my custom workflow which is cloning a record successfully but the problem is after cloning a record. I am not able to open my cloned record in the mean while or in real time.
So that I changed my mind and start writing JS which is working successfully but the problem is I have to retrieve many to many relationship records through JS and I am not able to find any method to retrieve. Is there any way that solve my problem?
Thank you
Regards,
AW
The problem as I showed in the code above in on the create function, that you have to make sure that you don't clone the primary key of the record that you are cloning, which will give you a duplicate record error.
Notice here, that for the primary key, I don't copy the field, but all other fields I do:
case "new_entitynameid":
break;
default:
newEntity[attributeName] = attributeValue;
break;
Hope this resolves the issue.
Hi Aric and Pawel
I wrote custom workflow and run it through run workflow option. I have copied all the field in my logic and create new record I have below error:
What I have to do to resolve this one?
Thank you
Regards,
AW
The logic is pretty simple.
1. Create a action under processes to clone the new record. You don't need to enter any input/output parameters
2. Add javascript code to your page to execute the clone method. You can use the process.js to simplify your logic.
function executeClone()
{
var entityId = Xrm.Page.data.entity.getId();
var entityName = "new_entity";
var messageName = "new_clonemessage";
var success = callCloneAction(entityId, entityName, messageName, callback);
if (success) {
}
}
function callCloneAction(entityId, entityName, messageName, name) {
var inputParams =
[
{
key: "Target",
type: Process.Type.EntityReference,
value: new Process.EntityReference(entityName, entityId)
}
];
var success = callProcessAction(entityId, entityName, messageName, inputParams);
return success;
}
function callProcessAction(entityId, entityName, messageName, inputParams) {
var success = true;
Process.callAction(messageName, inputParams,
function (params) {
// Success
var result = "";
for (var i = 0; i < params.length; i++) {
result = params[i].key + "=" + params[i].value + ";";
}
// alert(result);
success = true;
},
function (e, t) {
// Error
success = false;
alert(e);
if (window.console && console.error)
console.error(e + "\n" + t);
}
);
return success;
}
3. Create a plugin to execute the process
4. Add a function to retrieve the current entity values:
private Entity RetrieveData(string entityName, Guid entityId)
{
Entity custom = service.Retrieve(entityName, entityId, new ColumnSet(true));
return custom;
}
5. Add a function to create the new entity:
private Guid CreateNewEntity(Entity current)
{
Entity newEntity = new Entity(myEntity.EntityLogicalName);
foreach (KeyValuePair<String, Object> attribute in newEntity.Attributes)
{
string attributeName = attribute.Key;
object attributeValue = attribute.Value;
switch (attributeName.ToLower())
{
case "new_entitynameid":
break;
default:
newEntity[attributeName] = attributeValue;
break;
}
}
try
{
Guid newEntityId = service.Create(newEntity);
return newEntityId;
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in the CreateNewEntity function of the plug-in.", ex);
}
}
That's basically it.
Hope this helps...
Good luck.
You need to create and action/plugin/custom activity that will do the cloning logic and run it under this button (which you can add to your custom entity using Ribbon Workbench). This is not trivial to do correctly, so I will not post the code here, but I believe that it would be a nice training for you to implement such function. There are also many third-party solutions for such functionality if you don't want to write it by yourself.
Hi Thomas,
I think the way you are saying it is not possible.
Thank you
Regards,
AW
Could you not go into the Ribbon Workbench and copy the functionality of 'Clone' into your new custom button?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156