Hi Experts,
I have an issue with the unified interface, in the classic interface when ever user try to create an email from case activities timeline. by default email to field used to populate with the account, in UCI this is changed and populating with contact value. So to fix this issue i wrote Jscript to get the account from related incident record and update it on Email to field. it's coming up with not found error.
can someone please let me know where the error is? here is the Jscript
Any help would be greatly appreciated.
Thanks Leah, I have now updated the status
Sorry for not coming back quickly. Yes this works well. I have simplified the Jscript using rest builder and WebApi
Hi Partner,
Has the problem been solved? Any updates?
Please click Yes under "Did this answer your question?" to close this thread.
Thanks.
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.
Hi scopecrm,
The code that get id of ‘new_organisation’ field exsits error, you need write as following:
function UpdateToField(executionContext) { var formContext = executionContext.getFormContext(); var lookup = formContext.getAttribute("regardingobjectid").getValue(); // case lookup on email form var newid = lookup[0].id.slice(1, -1); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() "/api/data/v9.1/incidents(" newid ")?$select=_new_organisation_value", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var result = JSON.parse(this.response); var _new_organisation_value = result["_new_organisation_value"];//id var _new_organisation_value_formatted = result["_new_organisation_value@OData.Community.Display.V1.FormattedValue"];//name var _new_organisation_value_lookuplogicalname = result["_new_organisation_value@Microsoft.Dynamics.CRM.lookuplogicalname"];//entity type if (_new_organisation_value != null) { var value = new Array(); value[0] = new Object(); value[0].id = _new_organisation_value; value[0].name = _new_organisation_value_formatted; value[0].entityType = _new_organisation_value_lookuplogicalname; formContext.getAttribute("to").setValue(value); //set the lookup value finally } else alert("organisation is null"); } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); }
Test:
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.
Hi Leah, Thanks for checking this for me. However we have created a custom attribute on case form "new_organisation". this field is populated and has value. I am still getting "not found" error.
Hi scopecrm,
The ‘To’ field value of the email is filled with the value of the ‘customer’ field in the case form.
The ‘customer’ field is special, which type is customer. You can select both account and contact records.
So your JS code can’t find account value if you fill ‘Customer’ field with contacts.
If you want to fill email ‘to’ field with contacts, you must fill case form ‘customer’ field with contacts.
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.
André Arnaud de Cal...
291,979
Super User 2025 Season 1
Martin Dráb
230,848
Most Valuable Professional
nmaenpaa
101,156