The post submitted before I was finished. Below is the code I was referencing.
function emailFromCase(executionContext)
{
var formContext = executionContext.getFormContext();
var CREATEDON = 1;
var formType =formContext.ui.getFormType();
if (formType == CREATEDON)
{
regardingOnchange(executionContext);
}
}
function regardingOnchange(executionContext)
{
var formContext = executionContext.getFormContext();
if (formContext.data.entity.attributes.get("regardingobjectid").getValue() != null)
{
var regarding = formContext.data.entity.attributes.get("regardingobjectid").getValue()[0].entityType;
var id = formContext.data.entity.attributes.get("regardingobjectid").getValue()[0].id;
var guid = id.replace(/{/g, "").replace(/}/g, "");
if (regarding != null && guid != null)
{
if (regarding == "incident")
{
getCaseDetails(executionContext,guid);
}
}
}
}
function getCaseDetails(executionContext,recordId)
{
// alert(recordId);
var formContext = executionContext.getFormContext();
var serverUrl = formContext.context.getClientUrl();
var result;
var oDataEndpointUrl = serverUrl + "/api/data/v9.2/incidents?$select=title,ticketnumber&$filter=incidentid eq " + recordId + "";
//alert(oDataEndpointUrl);
var service = new XMLHttpRequest();
service.open("GET", oDataEndpointUrl, true);
service.setRequestHeader("OData-MaxVersion", "4.0");
service.setRequestHeader("OData-Version", "4.0");
service.setRequestHeader("Accept", "application/json");
service.setRequestHeader("Content-Type", "application/json;charset=utf-8");
service.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
service.setRequestHeader("Prefer", "odata.maxpagesize=50");
service.onreadystatechange = function ()
{
if (service.readyState == 4)
{
service.onreadystatechange = null;
if (service.status == 200)
{
var requestResults = JSON.parse(this.response);
if (requestResults != null && requestResults.value.length > 0)
{
for (var i = 0; i < requestResults.value.length; i++)
{
var caseName = requestResults.value[i]["title"];
var caseNumber = requestResults.value[i]["ticketnumber"];
var subj = caseName + " - " + caseNumber;
}
//alert(subj);
formContext.getAttribute("subject").setValue(subj);
}
}
}
}
service.send();
}