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.

  • Suggested answer
    Wahaj Rashid Profile Picture
    Wahaj Rashid 11,321 on at
    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);
    
                }
            }
    
        }
    
    }

    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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,468 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,289 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans