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 :
Microsoft Dynamics CRM (Archived)

Error with formContext

(0) ShareShare
ReportReport
Posted on by 2

I am getting an error when I try to call the following function from Dynamics 365 (CRM ver 9.0)

function addTask(executionContext) {
var formContext = executionContext.getFormContext();
Xrm.Utility.openEntityForm('task', null, {
pId: formContext.data.entity.getId().replace(/{|}/g, ''),
pType: Mscrm.EntityPropUtil.EntityTypeName2CodeMap[formContext.data.entity.getEntityName()],
pName: formContext.getAttribute('name').getValue()
});
}

Using browser debugger, I captured the following error:

TypeError: Unable to get property 'EntityTypeName2CodeMap' of undefined or null reference
 at addTask

I am not seeing what is causing the problem.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at

    Try this:

    function addTask(executionContext) {
    
    var formContext = executionContext.getFormContext();
    
    Xrm.Utility.openEntityForm('task', null, {
    
    pId: formContext.data.entity.getId().replace(/{|}/g, ''),
    
    pType: formContext.data.entity.getEntityName(),
    
    pName: formContext.getAttribute('name').getValue()
    
    });
    
    }


    It should work. Not sure from where you copied "Mscrm.EntityPropUtil.EntityTypeName2CodeMap"

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    You should start to change the JS format as well since you are using crm online.

    docs.microsoft.com/.../openform

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    It seems you are trying to open a new task form and populating the account. You could try this (pass the typecode manuall i.e. 1

    function addTask(executionContext) {

    var formContext = executionContext.getFormContext();

    Xrm.Utility.openEntityForm('task', null, {

    pId: formContext.data.entity.getId().replace(/{|}/g, ''),

    pType: 1,

    pName: formContext.getAttribute('name').getValue()

    });

    }

    Also, ensure that you are passing the formxcontext when you register the method.

    Hope this helps.

  • wperkinson3 Profile Picture
    2 on at

    Thank you sir.  This worked perfectly.

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans