Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

Auto populating data based on sub-grid quick create

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,319 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)

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,349 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,212 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans