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();“GET”, sQuery, false); //sync
request.setRequestHeader(“Accept”, “application/json”);
request.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);

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

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

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


// This function 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;
return null;

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