Dear Andrew,
thank you very much for your input and help that helped me to learn something new.
starting from your inputs I tried looking for the ConvertActivity action in the Organization Odata metadata file but I found nothing
so as next I opened the Google Chrome Dev tool and debugged the code until I found the ConvertActivity action in the Dynamics core JS files.
I found the information that I needed in these two JS (that I un minified) files
- ServiceCommandBarActions.js: formatted
- ClientUtility.js: formatted
the functions that I was looking for are
// ServiceCommandBarActions.js:formatted
this.convertToCase = function(successCallback, errorCallback, targetEntitySubject, activityId, activityTypeCode, customerId, customerTypeCode, ownerId, ownerTypeCode, subjectId, subjectTypeCode, logResponse) {
_this.WatermarkingStartMarkerWrapper("convertToCase");
var caseRecord = _this.getCaseEntityRecord(targetEntitySubject, activityId, activityTypeCode, customerId, customerTypeCode, ownerId, ownerTypeCode, subjectId, subjectTypeCode);
var entityName = CrmService.ClientUtil.getEntityName(activityTypeCode);
var convertActivityRequest = new ODataContract.ConvertActivityRequest({
guid: activityId
},entityName,caseRecord,CrmService.EntityNames.Incident,logResponse);
Xrm.WebApi.online.execute(convertActivityRequest).then(successCallback, errorCallback);
_this.WatermarkingEndMarkerWrapper("convertToCase");
};
this.getCaseEntityRecord = function (targetEntitySubject, activityId, activityTypeCode, customerId, customerTypeCode, ownerId, ownerTypeCode, subjectId, subjectTypeCode) {
_this.WatermarkingStartMarkerWrapper("getCaseEntityRecord");
var caseRecord = {};
caseRecord['incidentid'] = ClientUtility.Guid.newGuid();
caseRecord['@odata.type'] = "#Microsoft.Dynamics.CRM.incident";
caseRecord['title'] = targetEntitySubject;
if (customerId) {
if (customerTypeCode === CrmService.EntityTypeCodes.Account) {
caseRecord["customerid_account@odata.bind"] = "/accounts(" ClientUtility.Guid.create(customerId) ")";
}
else if (customerTypeCode === CrmService.EntityTypeCodes.Contact) {
caseRecord["customerid_contact@odata.bind"] = "/contacts(" ClientUtility.Guid.create(customerId) ")";
}
}
if (subjectId && subjectId.length > 0) {
caseRecord["subjectid@odata.bind"] = "/subjects(" ClientUtility.Guid.create(subjectId[0].id) ")";
}
if (ownerId) {
caseRecord["ownerid@odata.bind"] = "/systemusers(" ClientUtility.Guid.create(decodeURIComponent(ownerId)) ")";
}
_this.WatermarkingEndMarkerWrapper("getCaseEntityRecord");
return caseRecord;
};
// ClientUtility.js:formatted
function(t) {
var e = function() {
function t(t, e, r, n, a, i) {
this.ActivityId = t,
this.ActivityEntityName = e,
this.TargetEntity = r,
this.TargetEntityName = n,
this.CreateCampaignResponse = a,
ClientUtility.DataUtil.isNullOrUndefined(i) || (this.ShouldMarkComplete = i)
}
return t.prototype.getMetadata = function() {
var t = null;
return t = ClientUtility.DataUtil.isNullOrUndefined(this.ShouldMarkComplete) ? {
boundParameter: null,
parameterTypes: {
ActivityId: {
typeName: "Edm.Guid",
structuralProperty: 1
},
ActivityEntityName: {
typeName: "Edm.String",
structuralProperty: 1
},
TargetEntity: {
typeName: "Microsoft.Dynamics.CRM.crmbaseentity",
structuralProperty: 5
},
TargetEntityName: {
typeName: "Edm.String",
structuralProperty: 1
},
CreateCampaignResponse: {
typeName: "Edm.Boolean",
structuralProperty: 1
}
},
operationName: "ConvertActivity",
operationType: 0
} : {
boundParameter: null,
parameterTypes: {
ActivityId: {
typeName: "Edm.Guid",
structuralProperty: 1
},
ActivityEntityName: {
typeName: "Edm.String",
structuralProperty: 1
},
TargetEntity: {
typeName: "Microsoft.Dynamics.CRM.crmbaseentity",
structuralProperty: 5
},
TargetEntityName: {
typeName: "Edm.String",
structuralProperty: 1
},
CreateCampaignResponse: {
typeName: "Edm.Boolean",
structuralProperty: 1
},
ShouldMarkComplete: {
typeName: "Edm.Boolean",
structuralProperty: 1
}
},
operationName: "ConvertActivity",
operationType: 0
}
}
,
t
}();
t.ConvertActivityRequest = e
}
starting from these functions and using also Google Chrome Dev tools and this link
//Google chrome Dev tool Console
//carldesouza.com/.../
I wrote this code that helped me
var ActivityId = {guid: "{0661A625-C70D-ED11-82E4-000D3A2BFA5A}"};
var ActivityEntityName = "email";
var TargetEntity = {};
TargetEntity['incidentid'] = "{3d1da7b8-6e2a-47ca-922d-d36dbca62c79}" ;
TargetEntity['@odata.type'] = "#Microsoft.Dynamics.CRM.incident";
TargetEntity['title'] = "TEST SUBJECT FAKE NAME ";
TargetEntity["customerid_contact@odata.bind"] = "/contacts(1454206c-2034-ed11-9db1-000d3ab6fe31)";
TargetEntity["subjectid@odata.bind"] = "/subjects(7ef4ca58-8efa-e811-a95c-000d3a442d08)";
var TargetEntityName = "incident";
var CreateCampaignResponse = false;
var req = {};
req.ActivityId = ActivityId;
req.ActivityEntityName = ActivityEntityName;
req.TargetEntity = TargetEntity;
req.TargetEntityName = TargetEntityName;
req.CreateCampaignResponse = CreateCampaignResponse;
req.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {
ActivityId: {
typeName: "Edm.Guid",
structuralProperty: 1
},
ActivityEntityName: {
typeName: "Edm.String",
structuralProperty: 1
},
TargetEntity: {
typeName: "Microsoft.Dynamics.CRM.crmbaseentity",
structuralProperty: 5
},
TargetEntityName: {
typeName: "Edm.String",
structuralProperty: 1
},
CreateCampaignResponse: {
typeName: "Edm.Boolean",
structuralProperty: 1
}
},
operationName: "ConvertActivity",
operationType: 0
};
};
Xrm.WebApi.online.execute(req).then(
function (data) {
var e = data;
debugger;
},
function (error) {
debugger;
var errMsg = error.message;
}
);
this code is working for me at least.
you fixed my issue as I was looking for a solution like you suggested (even though I am not sure I will use that function)