The Regarding Object is Not Set When Creating a New Appointment Activity from a Sub-Grid

When you create an activity from the context of a record, the new Activity should automatically have the Regarding Object set to the parent record.  As of Rollup 11, this behavior is not working when the activity is a sub-grid.

In our scenario, we have a custom entity called Event.  We have added a sub-grid for Appointments of a particular event associated with the Event (we have a custom field on Event called “Type”).

To replicate the bug:

1.) First, we add Appointments (added as a sub-grid using a custom view called Agenda Items).

Regarding Object Not Set

2.) Next, we open the Event

Regarding Object Not Set

3.) Then we try to add a new Appointment… notice the regarding object is not set:

Regarding Object Not Set

To fix the issue, we will add code to the Appointment On Load to see if we are on a Create form and if we came from the subgrid on the Event.  If so, we’ll be able to grab the Parent and set the Regarding Object.  See the included code below which lets you accomplish this!

Use this Code:

function EventOnLoad()
{
// is this a create form?
if (Xrm.Page.ui.getFormType() == 1)
{
// The query string has the parent’s id and object type code
var queryStringObject = Xrm.Page.context.getQueryStringParameters();

if (queryStringObject != null)
{
// let’s go get the event’s object type code.
var eventOTC = getEntityOTC(“ems_event”);

// If the parent is an event, then we need to set the regarding object.
// NOTE: If this appointment was created from the left navigation _CreateFromType will be null and the code won’t execute (which we want)
if (eventOTC == queryStringObject._CreateFromType)
{
var eventName = “”;

var sQuery = _rootSite + “/XRMServices/2011/organizationData.svc/ems_eventSet?$select=ems_name&$filter=ems_eventId eq guid'” + queryStringObject._CreateFromId + “‘”;
var request = new XMLHttpRequest();
request.open(“GET”, sQuery, false); //sync
request.setRequestHeader(“Accept”, “application/json”);
request.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
request.send();

var retrievedData = JSON.parse(request.responseText).d;

if (retrievedData.results[0].ems_name != null)
{
eventName = retrievedData.results[0].ems_name;

var olookup = new Object();
olookup.id = queryStringObject._CreateFromId;
olookup.entityType = “ems_event”;
olookup.name = eventName;
var olookupValue = new Array();
olookupValue[0] = olookup;

Xrm.Page.getAttribute(“regardingobjectid”).setValue(olookupValue);
}
}
}
}
}

// This funtion gets the Object Type Code for any entity
function getEntityOTC(entityName)
{
var lookupService = new RemoteCommand(“LookupService”, “RetrieveTypeCode”);
lookupService.SetParameter(“entityName”, entityName);

var result = lookupService.Execute();
if (result.Success && typeof result.ReturnValue == “number”)
{
return result.ReturnValue;
}
else
{
return null;
}
}

Phone: 312-602-4000
Email: marketing@westmonroepartners.com
222 W. Adams
Chicago, IL 60606
Show Buttons
Share On Facebook
Share On Twitter
Share on LinkedIn
Hide Buttons