- Navigate to Settings | Solutions | Packt.
- Click on Web Resources and click on New.
- Create a JScript called packt_/js/angular.min.js and upload the angular.min.js file that you have downloaded from https://angularjs.org/.
- Create a JScript called packt_/js/packt.app.js with the following content:
var app = angular.module("packtApp", []);
- Create a JScript called packt_/js/packt.controller.js with the following content:
app.controller('packtController', function
($scope, packtCrmService) {
$scope.dataLoading = true;
packtCrmService.loadAttributesFromCurrentEntity().then(
function (result) {
if (result.status == 200) {
$scope.attributes = result.data;
}
else{
alert("Error while loading attributes. " +
result.status);
}
}).finally(function () {
$scope.dataLoading = false;
});
});
- Create a JScript called packt_/js/packt.services.js with the following content:
app.service('packtCrmService', function ($http, $location)
{
this.loadAttributesFromCurrentEntity = function () {
var entityGuid =
window.location.href.substring(window.location.href.indexOf("=")+1);
var attributesUrl = window.location.origin +
'/api/data/v8.2/EntityDefinitions(' + entityGuid +
')?$select=LogicalName&$expand=Attributes(
$select=LogicalName;$filter=AttributeType eq
Microsoft.Dynamics.CRM.AttributeTypeCode'Picklist')';
var attributesRequest = {
method: 'GET',
url: attributesUrl,
headers: {
'Prefer': 'odata.include-
annotations="OData.Community.Display.V1.FormattedValue"'
}
}
var attributesPromise = $http(attributesRequest).then(
function (response) {
return {
"status": response.status,
"data": response.data.Attributes
};
},
function (response) {
return {
"status": response.status,
"data": response.statusText
};
}
);
return attributesPromise;
}
});
- Create an HTML resource with the name packt_/attributes.htm and the following content:
<html>
<head>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/packt.app.js"></script>
<script type="text/javascript" src="js/packt.controller.js"></script>
<script type="text/javascript" src="js/packt.service.js"></script>
<meta charset="utf-8">
<title>Attributes V1.14</title>
</meta>
</head>
<body>
<div ng-app="packtApp" ng-controller="packtController">
<div ng-if="dataLoading">Loading analysis...</div>
<ul ng-repeat="attribute in attributes" ng-
if="dataLoading === false">
<li>{{ attribute.LogicalName }}</li>
</ul>
</div>
</body>
</html>
- Under Entities | Contact | Forms, double-click on the Main form.
- Click on INSERT | Web Resource and enter the following details:
- Web: resource packt_attributes.htm
- Name: WebResources_attributehtm
- Label: Attributes
- Custom Parameter (data): <Contact entity MetadataId in this example: 608861bc-50a4-4c5f-a02c-21fe1943e2cf>
- Click on OK, and then on the HOME tab, click on Save and Close.
- Back in your solution, click on Publish All Customizations.