Skip to content

Commit

Permalink
1. Modify "All Fields" and "System User Roles" to use WebAPI.
Browse files Browse the repository at this point in the history
2. Add es6-shim.js as marker script.
  • Loading branch information
rajyraman committed Jul 8, 2019
1 parent 532ad5d commit 3c1e252
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 57 deletions.
4 changes: 2 additions & 2 deletions app/manifest.json
Expand Up @@ -30,7 +30,7 @@
"https://*/*"
],
"web_accessible_resources" : ["Sdk.Soap.min.js","levelup.extension.js"],
"version" : "3.3.1",
"version_name" : "3.3.1",
"version" : "3.3.2",
"version_name" : "3.3.2",
"manifest_version" : 2
}
3 changes: 2 additions & 1 deletion app/scripts/app/app.ts
Expand Up @@ -10,7 +10,8 @@ module LevelUp{
this.isCRMPage = Array
.from(document.scripts)
.some(x => x.src.indexOf("/_static/_common/scripts/PageLoader.js") !== -1
|| x.src.indexOf("/uclient/scripts/app.js") !== -1
|| x.src.indexOf("/uclient/scripts/app.js") !== -1
|| x.src.indexOf("/uclient/scripts/es6-shim.js") !== -1
|| x.src.indexOf("/_static/_common/scripts/crminternalutility.js") !== -1);
}

Expand Down
11 changes: 9 additions & 2 deletions app/scripts/inject/levelup.common.utility.ts
Expand Up @@ -40,7 +40,7 @@ module LevelUp {
return this._version;
}

fetch(entityName: string, attributes?: string, filter?: string): Promise<Array<any>> {
fetch(entityName: string, attributes?: string, filter?: string, id?: string, fetchXML?: string): Promise<Array<any>> {
let headers = new Headers({
"Accept": "application/json",
"Content-Type": "application/json; charset=utf-8",
Expand All @@ -51,16 +51,23 @@ module LevelUp {
"Accept": "application/json",
"Content-Type": "application/json; charset=utf-8",
"OData-MaxVersion": "4.0",
"OData-Version": "4.0"
"OData-Version": "4.0",
"Prefer": "odata.include-annotations=\"*\""
});
serviceUrl = `${Xrm.Page.context.getClientUrl()}/api/data/v${Xrm.Page.context.getVersion().substr(0,3)}/${entityName}`;
}
if(id){
serviceUrl += `(${id})`;
}
if (attributes) {
serviceUrl += `?$select=${attributes}`;
}
if (filter) {
serviceUrl += `&$filter=${filter}`;
}
if (fetchXML) {
serviceUrl += `?fetchXml=${encodeURI(fetchXML)}`;
}
return fetch(serviceUrl, {
method: 'GET',
headers: headers,
Expand Down
43 changes: 16 additions & 27 deletions app/scripts/inject/levelup.forms.ts
Expand Up @@ -404,34 +404,23 @@ module LevelUp {
}

allFields() {
CrmSdk.Async.retrieve(
this.utility.Xrm.Page.data.entity.getEntityName(),
this.utility.Xrm.Page.data.entity.getId().substr(1, 36),
new CrmSdk.ColumnSet(true),
entity => {
let attributes = entity.getAttributes()
, formattedAttributes = entity.getFormattedValues()
, attributeNames = attributes.getNames()
, formAttributes = this.utility.Xrm.Page.getAttribute().map(x => x.getName())
, attributesNotInForm = attributeNames.filter(x => formAttributes.indexOf(x) > -1 || !this.utility.Xrm.Page.getControl(x) || !this.utility.Xrm.Page.getControl(x).getVisible()),
resultsArray = [{ cells: ['Attribute Name', 'Value'] }];

let attributeValues = attributesNotInForm.forEach(x => {
let attribute = attributes.getAttributeByName(x),
attributeValue = attribute.getValue();
if (formattedAttributes.containsName(x)) {
let formattedValue = formattedAttributes.getItem(x).getValue();
if (formattedValue) {
resultsArray.push({ cells: [x, formattedAttributes.getItem(x).getValue()] });
}
}
else {
resultsArray.push({ cells: [x, attribute.getType() !== 'entityReference' ? attributeValue : attributeValue.getName() || attributeValue.getId()] });
let entityId = this.utility.Xrm.Page.data.entity.getId();
if (entityId) {
let entityName = this.utility.Xrm.Page.data.entity.getEntityName();
let resultsArray = [{ cells: ['Attribute Name', 'Value'] }];
this.utility.fetch(`EntityDefinitions(LogicalName='${entityName}')`, 'EntitySetName').then(entity => {
if (entity && entity.EntitySetName) {
this.utility.fetch(entity.EntitySetName, null, null, entityId.substr(1,36).toLowerCase()).then(r=>{
var keys = Object.keys(r);
keys.forEach(k=>{
resultsArray.push({ cells: [k, r[k]] });
});
console.log(r);
this.utility.messageExtension(resultsArray, 'allFields');
})
}
});
this.utility.messageExtension(resultsArray, 'allFields');
},
error => console.log(error));
});
}
}

toggleTabs() {
Expand Down
32 changes: 15 additions & 17 deletions app/scripts/inject/levelup.servicecalls.ts
Expand Up @@ -51,36 +51,34 @@ module LevelUp {

allUserRoles() {
let resultsArray: any[] = [{ cells: ['Business Unit', 'Role', 'User', 'AD Name'] }];
CrmSdk.Async.retrieveMultiple(new CrmSdk.Query.FetchExpression(`
this.utility.fetch('systemusers', null, null, null, `
<fetch>
<entity name="systemuser" >
<attribute name="domainname" />
<attribute name="businessunitid" />
<attribute name="fullname" />
<link-entity name="systemuserroles" from="systemuserid" to="systemuserid" alias="systemuserroles">
<filter>
<condition entityname="role" attribute="parentroleid" operator="null" />
</filter>
<link-entity name="systemuserroles" from="systemuserid" to="systemuserid" link-type="outer" alias="systemuserroles" >
<attribute name="roleid" />
<attribute name="systemuserid" />
<link-entity name="role" from="roleid" to="roleid" alias="role">
<link-entity name="role" from="roleid" to="roleid" link-type="outer" alias="role" >
<attribute name="name" />
<order attribute="name" />
<filter>
<condition attribute="parentroleid" operator="null" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>`),
results => {
let entities = results.getEntities().toArray();
let cells = entities.forEach(x => {
let attributes = x.getAttributes(),
roleId = attributes.getAttributeByName('systemuserroles.roleid').getValue(),
roleName = attributes.getAttributeByName('role.name').getValue(),
userId = attributes.getAttributeByName('systemuserroles.systemuserid').getValue(),
userName = attributes.getAttributeByName('fullname').getValue();
</fetch>`).then(entities => {
console.log(entities);
let cells = entities.forEach(attributes => {
let roleId = attributes['systemuserroles.roleid'] || 'No Role',
roleName = attributes['role.name'] || 'No Role',
userId = attributes['systemuserid'],
userName = attributes['fullname'];

resultsArray.push({
bu: attributes.getAttributeByName('businessunitid').getValue().getName(),
bu: attributes['_businessunitid_value@OData.Community.Display.V1.FormattedValue'],
role: {
id: roleId,
name: roleName,
Expand All @@ -91,7 +89,7 @@ module LevelUp {
name: userName,
url: `${this.utility.clientUrlForParams}etn=systemuser&id=${userId}&newWindow=true&pagetype=entityrecord`
},
adname: attributes.getAttributeByName('domainname').getValue()
adname: attributes['domainname']
});
});
this.utility.messageExtension(resultsArray, 'allUserRoles');
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "Levelup-for-Dynamics-CRM-365",
"private": true,
"version": "3.3.1",
"version": "3.3.2",
"description": "Quickly perform advanced/hidden actions in Dynamics CRM/365, without bookmarklets.",
"scripts": {
"clean": "gulp clean --vendor=chrome & gulp clean --vendor=firefox & gulp clean --vendor=edge",
Expand Down Expand Up @@ -33,6 +33,7 @@
"devDependencies": {
"@types/chrome": "0.0.66",
"@types/lodash": "^4.14.109",
"@types/xrm": "^9.0.14",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
Expand Down Expand Up @@ -62,7 +63,5 @@
"typescript": "^2.8.3",
"webpack2": "^3.11.1"
},
"dependencies": {
"@types/xrm": "^8.2.5"
}
"dependencies": {}
}

0 comments on commit 3c1e252

Please sign in to comment.