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)

How to build angular (v2.0 and above) project containing "Xrm"

(0) ShareShare
ReportReport
Posted on by 15

While building an angular project containing xrm object I'm getting an error stating xrm is undefined. Is there a way to include xrm in angular versions 2.0 and above? Currently I'm using version 7. I saw a workaround for doing this at https://github.com/kip-dk/angular-xrm-webresource#start-of-content

import { Component, OnInit, ViewChild} from '@angular/core';
import {MatSort, MatTableDataSource, MatPaginator} from '@angular/material';

interface XrmContext { getClientUrl(): string; }

@Component({ selector: 'app-table-sorting-example', templateUrl: './table-sorting-example.component.html', styleUrls: ['./table-sorting-example.component.css'] })
export class TableSortingExampleComponent implements OnInit {
  displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
  dataSource = new MatTableDataSource(ELEMENT_DATA);

  @ViewChild(MatPaginator) paginator: MatPaginator;
  @ViewChild(MatSort) sort: MatSort;
  applyFilter(filterValue: string) {
    this.dataSource.filter = filterValue.trim().toLowerCase();
  }
  ngOnInit() {
    this.dataSource.sort = this.sort;
    this.dataSource.paginator = this.paginator;
    alert("test");
    alert("url: "+this.getClientUrl()+"\nwindow location href: "+window.location.href);
    debugger;
    console.log(window.location.host);
    Xrm.Page.context.getClientUrl();
  }
  getClientUrl() {
    if (window.parent != null && window.parent['Xrm'] != null) {
        var x = window.parent["Xrm"]["Page"]["context"] as XrmContext;
        if (x != null) {
            return x.getClientUrl();
        }
    }
    // fallback for development environment
    return "http://localhost:4200";
  } 
}

07218.error.png

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    The "xrm" property you are referencing is not CRM properties , I guess it taking from the third party library "shared\xrm.service.ts" , make sure you added the library. Sorry I have not tried just to see the reference you shared.

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