2
votes

I am using CRM 2013 on-premise with UR1 installed

I have a custom entity with a subgrid on it looking at related "tasks" which looks like this: subgrid on custom entity

Whenever I create a task from the subgrid using the "+" button in the top right hand corner of the subgrid; the "Regarding" field of the newly created task remains blank. When it should be populated by a lookup to the record it was created from.

Empty Regarding field on task created from custom entity

I have javascript on the task entity which checks the "Regarding" field to check what kind of entity it was created from (if it was created from one) and gets certain field values from the calling entity to populate fields on the task.

Since the "Regarding" field is never filled the Javascript never fires - and the fields do not populate.

When the record is saved, if the regarding field is blank (I have not manually filled it in) - it will eventually be populated by the correct record about 10 - 15 seconds later if you refresh the page. Then the correct fields will be populated and the user is able to edit the option set values and save again. This is not ideal for the user as they would like it to be one fluid action.

Is there any way around this problem?

EDIT for future browsers of this question:

Found a partial work around. If you use an "Activity" subgrid rather than a "Task" subgrid the field will populate. This has a drawback though as you cannot edit the "Activity" subgrid's view to show "Task" specific fields.

2
The new editable sub-grid don't seem to have the same bug. If you add a Task from that sub-grid the regarding is set as expected.Andrew Clear

2 Answers

1
votes

Ran into this same issue. The way I got around it was to add a look-up to the custom entity on the form (we put this on a hidden tab). When the Task gets created from the custom entity the look-up will be populated. You can then use that look-up to grab the values that you need to populate, including the regarding field. Not the most elegant, but it works.

1
votes

I also ran into this problem and went with a pure JS approach to resolving. On load of the task form, call populateRegarding().

This works because even though the regarding lookup doesn't populate by default, the query string parameters include _CreateFromType and _CreateFromId values.

This works in 2015, didn't test on earlier versions. Note that it is unsupported.

function populateRegarding() {
  var regarding = Xrm.Page.getAttribute("regardingobjectid"),
    createFromType = Xrm.Page.context.getQueryStringParameters()._CreateFromType,
    createFromId = Xrm.Page.context.getQueryStringParameters()._CreateFromId;

  if (!createFromId || !createFromType || 
      !regarding || regarding.getValue() !== null) {
    return;
  }

  var entityLogicalName = getEntityLogicalNameFromObjectTypeCode(createFromType);

  regarding.setValue([{
    id: createFromId,
    entityType: entityLogicalName,
    name: "Hardcoded Name" // TODO: retrieve name dynamically
  }]);
}

// This method uses an undocumented object and is therefore unsupported. 
// You could implement a supported version of this function by querying for
// metadata, but that would be very expensive.
function getEntityLogicalNameFromObjectTypeCode(otc) {
  var map = Mscrm.EntityPropUtil.EntityTypeName2CodeMap,
    logicalName;

  otc = Number(otc); // convert string to number

  for (logicalName in map) {
    if (!map.hasOwnProperty(logicalName)) { continue; }

    if (map[logicalName] === otc) {
      return logicalName;
    }
  }
}