Hi everyone,
Could we convert an email to a case using Webapis either specific dynamics 365 actions?
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
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)
Hi,
In essence you converted an email to a case (for which the backend name is incident) so the id of the case you created is the incidentid. The recordId you were referring to in the afore mentioned comments is the id of the process job for the ConvertActivity process you called.
Personally I would use queues and automatic record creation & routing that is an out of the box feature in Dynamics and you would spend less time developing a solution and just configure it :)
Another easy way would be to create a workflow on email to check messages with the direction of incoming (assuming it is just incoming messages you are concerned about) and who the receiving mailbox is and then create a case from there if the criteria is met.
Check out this link for Queues: learn.microsoft.com/.../automatically-create-update-records
Hope this helps.
Hello,
Here is how you can call actions using JavaScript:
learn.microsoft.com/.../execute
Here is how you can call an action using C#:
I have no idea in regards to incidentid - I would recommend checking if you have that record in the system.
in the Response, the Record Id is the Incident id of the created incident by ConvertActivity function
Hi Andrea,
First of all a big thank you for taking care and I am sorry for the delay in getting back to you.
I checked this afternoon with my team and now by myself
I went to dev env and opened the web browser dev tool and I had a look at the network trace I converted an email to a case
this was my request xyz.crm4.dynamics.com/.../ConvertActivity
this was the request payload (I don't understand what the incident is, very weird for me )
{"ActivityId":"{0661A625-C70D-ED11-82E4-000D3A2BFA5A}","ActivityEntityName":"email","TargetEntity":{"incidentid":"f40ebafc-b937-4e3f-aec0-031b1d8921db","@odata.type":"#Microsoft.Dynamics.CRM.incident","title":"ASasaSAs","customerid_contact@odata.bind":"/contacts(1454206c-2034-ed11-9db1-000d3ab6fe31)","subjectid@odata.bind":"/subjects(7ef4ca58-8efa-e811-a95c-000d3a442d08)"},"TargetEntityName":"incident","CreateCampaignResponse":false}
this was the Response (the record id
{"@odata.context":""RecordId":"9241459e-bf7c-ed11-81ad-000d3aaac3d1"} ">xyz.crm4.dynamics.com/.../$metadata
after that, I went to Postman (luckily I had already in ky workspace a collection with the correct authorization setting for dynamics)
I created a POS request like this xyz.crm4.dynamics.com/.../ConvertActivity
I put this request in the body of this string (that then I formatted as JSON)
for me it is working what I don't understand is that I marked it in red here
{"ActivityId":"{0661A625-C70D-ED11-82E4-000D3A2BFA5A}","ActivityEntityName":"email","TargetEntity":{"incidentid":"f40ebafc-b937-4e3f-aec0-031b1d8921db","@odata.type":"#Microsoft.Dynamics.CRM.incident","title":"ASasaSAs","customerid_contact@odata.bind":"/contacts(1454206c-2034-ed11-9db1-000d3ab6fe31)","subjectid@odata.bind":"/subjects(7ef4ca58-8efa-e811-a95c-000d3a442d08)"},"TargetEntityName":"incident","CreateCampaignResponse":false}
(the incidentid in my opinion makes no sense ).
Do you know how I can execute this HTTPS POST request inside my dynamics 365 JS or via plugin sdk ?
Regards and thanks lot for the support
Hello,
I did a quick check and there is a ConvertActivity message that can be utilized. Unfortunately, there is not a lot of info on how it can be used. It seems that it's not documented here - learn.microsoft.com/.../microsoft.crm.sdk.messages so if you use it - you're using it on your risk.
The way I found it is simple - I opened the browser developer tools (clicked F12) and performed the Conversion of the activity to Case. On the network Tab I found the trace of the API that was called.
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,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156