RE: Auto populating data based on sub-grid quick create
Hi,
When you create a task from subgrid it opens Task Quick Create form and by default sets regarding field (parent). You can register a JavaScript function on load of the task quick create form, which sets the value based on entity type of regarding lookup.
Here is an example with steps:
- Add your custom field to the Task Quick Create form.
- Register a Javascript function which fires on load of the form and sets value based on the entity type of the regarding lookup.
- Here is example code for your reference:
function onLoad_Set_Task_Type(executionContext) {
var formContext = executionContext.getFormContext();
// Set value only on Create Form
if (formContext.ui.getFormType() == 1) {
var entityType, lookupFieldObj;
// Get Regarding Lookup Object
lookupFieldObj = formContext.data.entity.attributes.get("regardingobjectid");
if (lookupFieldObj.getValue() != null) {
entityType = lookupFieldObj.getValue()[0].entityType;
// Set value based on regarding entity
if (entityType == "account") {
formContext.data.entity.attributes.get("new_whocalledme").setValue(100000000);
} else if (entityType == "opportunity") {
formContext.data.entity.attributes.get("new_whocalledme").setValue(100000001);
} else {
formContext.data.entity.attributes.get("new_whocalledme").setValue(100000002);
}
}
}
}
- Publish the form.
- Now when we create a task from Account or Opportunity, it sets the value of custom field accordingly.
When task created from Account
When task created from Opportunity
I hope this solves your problem.
Best,
Wahaj
(if it helped, mark it verified)