How to do it...

  1. Navigate to Settings | Solutions | Packt.
  2. Click on Web Resources and click on New.
  3. Create a JScript called packt_/js/angular.min.js and upload the angular.min.js file that you have downloaded from https://angularjs.org/.
  4. Create a JScript called packt_/js/packt.app.js with the following content:
var app = angular.module("packtApp", []); 
  1. 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;
});
});
  1. 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;
}
});
  1. 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>
  1. Under Entities | Contact | Forms, double-click on the Main form.
  2. 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>
  3. Click on OK, and then on the HOME tab, click on Save and Close.
  4. Back in your solution, click on Publish All Customizations.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.134.130