Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

How to get Client API execution context into Angular web resource

Posted on by

Hello,

I am using Angular web resources in my form. But I am not able to access formContext into my typescript component. 

If I want to access formContext I need to use Client API execution context.

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/clientapi-form-context

when I build my Angular web resource it generated the following javascript file. 

pastedimage1621926177418v1.png

How I can pass the execution context so that I can access it from my angular component ngOnInit event ?

pastedimage1621926485259v2.png

Regards

Mohammad

  • MOHAMMAD Profile Picture
    MOHAMMAD on at
    RE: How to get Client API execution context into Angular web resource

    Hi Leah,

    Thank you for your response.

    I am already using

    <script type="text/javascript" src ="../ClientGlobalContext.js.aspx"></script>

    npm install --save @types/xrm

    I need to get Attribute value.

    function displayName()

    {

    var firstName = Xrm.Page.getAttribute("firstname").getValue();

    var lastName = Xrm.Page.getAttribute("lastname").getValue();

    console.log(firstName + " " + lastName);

    }

    Xrm.Page object is deprecated and I need to use formContext

    function displayName(executionContext)

    {

    var formContext = executionContext.getFormContext(); // get formContext

    // use formContext instead of Xrm.Page

    var firstName = formContext.getAttribute("firstname").getValue();

    var lastName = formContext.getAttribute("lastname").getValue();

    console.log(firstName + " " + lastName);

    }

    If I use simple javascript I can easily pass formcontext on load event. But for angular, I don't know how to do that.

    Regards

    Mohammad

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get Client API execution context into Angular web resource

    Hi Mohammad,

    Not using formContext in the Angular web resource, you need use xrm to achieve it.

    Steps for using Xrm object in Angular application

    1.We need to add the following line of code to “Index.HTML”, as this will add the ClientGlobalContext to the Angular JS component.

    <script type="text/javascript" src ="../ClientGlobalContext.js.aspx"></script>

    2.Now we need to download and install the XRM tool libraries to our project, so please open your terminal and execute the below command:

    npm install --save @types/xrm

    3.Now we need to update the tsconfig.app.json file in our project. Need to add the value xrm in the types parameter.

    4.Now build the application and update the main.js file in Dynamics 365.

    If you are on Dynamics 365 version 9.x and above then you can directly use Xrm.WebApi to perform CRUD operations on CRM data. But if you are on 8.x and below then you would need to add reference of Web API in your Angular Application.

    For more detailed information, you can refer following links:

    Using Angular in Dynamics 365 CRM – Part II | Microsoft Dynamics 365 CRM Tips and Tricks (inogic.com)

    Accessing XRM In Angular Component In Dynamics CRM (c-sharpcorner.com)

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans