Hi,
I'm trying to clone a record -which is a Case (generally)
So I chose the path of doing with Java Script on ribbon button - "Duplicate Case"
Added button to Form Grid of "incident" entity in Ribbon WorkBench 2016 with Action by calling a JavaScript function named " DuplicateCase"
On click the button -> should take the details from current case and create new case, copy the details.
I'm able to take information from the current case but unable to create new case. Its giving me error which unable to understand.
I used Xrm.Utility.openEntityForm to open the new case which I want to copy the details into it.
Can you anyone help me in solving the problem. Below figure is error which I got.
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #541BFBBCDetail:<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts"><ActivityId>05c66d6a-3568-44a1-aeee-1ecd58cebb35</ActivityId><ErrorCode>-2147220970</ErrorCode><ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic"><KeyValuePairOfstringanyType><d2p1:key>CallStack</d2p1:key><d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string"> at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)</d2p1:value></KeyValuePairOfstringanyType></ErrorDetails><Message>System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #541BFBBC</Message><Timestamp>2017-03-13T20:15:49.6105446Z</Timestamp><ExceptionSource i:nil="true" /><InnerFault><ActivityId>05c66d6a-3568-44a1-aeee-1ecd58cebb35</ActivityId><ErrorCode>-2147220970</ErrorCode><ErrorDetails xmlns:d3p1="schemas.datacontract.org/.../System.Collections.Generic"><KeyValuePairOfstringanyType><d3p1:key>CallStack</d3p1:key><d3p1:value xmlns:d5p1="www.w3.org/.../XMLSchema" i:type="d5p1:string"> at Microsoft.Crm.Application.ParameterFilter.ValidateParameter(HttpRequest request, ArrayList parameterCollection, String key, String value, ParameterSources source, EntityType pageEntityType, FormAdditionalAllowedParameters additionalAllowedParameters) at Microsoft.Crm.Application.ParameterFilter.ValidateParameters(Page page, EntityType pageEntityType, Boolean alwaysEnableParameterChecking, FormAdditionalAllowedParameters formAdditionalAllowedParametersTemp) at Microsoft.Crm.Application.ParameterFilter.ValidateParameters(Page page, EntityType pageEntityType, FormAdditionalAllowedParameters formAdditionalAllowedParametersTemp) at Microsoft.Crm.Application.Controls.AppPage.ValidatePageParameters() at Microsoft.Crm.Application.Controls.AppPage.OnInit(EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</d3p1:value></KeyValuePairOfstringanyType></ErrorDetails><Message>System.InvalidOperationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #CAC77002</Message><Timestamp>2017-03-13T20:15:49.6105446Z</Timestamp><ExceptionSource i:nil="true" /><InnerFault i:nil="true" /><OriginalException i:nil="true" /><TraceText i:nil="true" /></InnerFault><OriginalException i:nil="true" /><TraceText i:nil="true" /></OrganizationServiceFault>
And My source Code :
function DuplicateCase() {
//get values from the Form
var CaseId = Xrm.Page.data.entity.getId();
var CaseTitle = Xrm.Page.data.entity.attributes.get("title").getValue();
if (Xrm.Page.data.entity.attributes.get("customerid").getValue() != null) {
var CustomerId = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].id;
var CustomerName = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;
var CustomerType = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].entityType;
alert(CustomerId);
alert(CustomerName);
alert(CustomerType);
}
if (Xrm.Page.data.entity.attributes.get("subjectid").getValue() != null) {
var SubjectId = Xrm.Page.data.entity.attributes.get("subjectid").getValue()[0].id;
var SubjectName = Xrm.Page.data.entity.attributes.get("subjectid").getValue()[0].name;
alert(SubjectId);
alert(SubjectName);
}
var CaseOriginCode = Xrm.Page.data.entity.attributes.get("caseorigincode").getValue();
alert(CaseOriginCode);
var CaseTypeCode = Xrm.Page.data.entity.attributes.get("new_casetypecode").getValue();
alert(CaseTypeCode);
var CaseDescription = Xrm.Page.data.entity.attributes.get("description").getValue();
alert(CaseDescription);
//define default values for new Incident record
var parameters = {};
if (CaseTitle != null) {
parameters["title"] = CaseTitle + " - COPY";
}
if (CustomerId != null && CustomerName != null) {
parameters["customerid"] = CustomerId;
parameters["customeridname"] = CustomerName;
parameters["customeridtype"] = CustomerType;
}
if (SubjectId != null && SubjectName != null) {
parameters["subjectid"] = SubjectId;
parameters["subjectidname"] = SubjectName;
}
if (CaseOriginCode != null) {
parameters["caseorigincode"] = CaseOriginCode;
}
if (CaseTypeCode != null) {
parameters["new_casetypecode"] = CaseTypeCode;
}
if (CaseDescription != null) {
parameters["description"] = CaseDescription;
}
if (CaseId != null && CaseTitle != null) {
parameters["new_parentcase"] = CaseId;
parameters["new_parentcasename"] = CaseTitle;
}
//pop incident form with default values
Xrm.Utility.openEntityForm("incident", null, parameters);
}
Thanks,
Deepthi