Tuesday, October 17, 2017

Setting regardingobjectid in the new v9.0+ api

In the pre-9.0 API, you could pull a few tricks to set the regardingid value in a new activity that you opened with openEntityForm.
The API has changed somewhat in 9.0+. The new API uses Xrm.Navigation.openForm with the arguments specified as an object:
const parameters = {}
nav.openForm({entityName: "contact", id: <guid or skip id attribute for a new one>, 
                openInNewWindow: false, useQuickCreateForm: true, 
                width: 1000, height: 1000}, parameters) 
The tricky part was always setting the regarding attribute. Now you can rather easily by doing:
const parameters = {
  regardingobjectid: JSON.stringfy({id: regardingObjectIdGUID, name: "name of regarding object",
    entityType: "contact"})
}  
The entityName should be the regarding entity's logical name. The id should not have braces ({}).
If you need to support both APIs and use webpack, use DefinePlugin to set a "CLIENT" variable to switch between the formats.

No comments:

Post a Comment