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 365 | Integration, Dataverse...
Suggested Answer

How to get Client API execution context into Angular web resource

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    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.

  • MOHAMMAD Profile Picture
    on at

    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

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 60 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 51

#3
Satyam Prakash Profile Picture

Satyam Prakash 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans