web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Auto populating data based on sub-grid quick create

(0) ShareShare
ReportReport
Posted on by 50

Hello,

My setup:

  • I have a custom option set field on the Task entity. 
  • I have the task subgrid on the Opportunity form for general task entry.
  • I also have a task subgrid on the account form and am adding another subgrid for task on the opportunity form. 

What I need: 

  • For the account form task subgrid, when creating a new task I need the custom option set to default to a specific value.
  • For the new task subgrid on the opportunity form I need:
    • the custom option set to default to a different specific value and auto-populate the due date to date of creation. 

How can I set a default value of a quick create based on which subgrid i'm creating from? Is this possible?

Thank you.

I have the same question (0)
  • Suggested answer
    Wahaj Rashid Profile Picture
    11,321 on at

    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);
    
                }
            }
    
        }
    
    }

    0572.pastedimage1607316321247v1.png

    • 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

    6746.pastedimage1607316500023v3.png

    When task created from Opportunity

    7180.pastedimage1607316423011v2.png

    I hope this solves your problem.

    Best,

    Wahaj

    (if it helped, mark it verified)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans