From 3c1e2526496bb5995a67f0adb83d5df656816dcc Mon Sep 17 00:00:00 2001 From: Natraj Yegnaraman Date: Mon, 8 Jul 2019 22:23:10 +1000 Subject: [PATCH] 1. Modify "All Fields" and "System User Roles" to use WebAPI. 2. Add es6-shim.js as marker script. --- app/manifest.json | 4 +- app/scripts/app/app.ts | 3 +- app/scripts/inject/levelup.common.utility.ts | 11 ++++- app/scripts/inject/levelup.forms.ts | 43 ++++++++------------ app/scripts/inject/levelup.servicecalls.ts | 32 +++++++-------- package-lock.json | 9 ++-- package.json | 7 ++-- 7 files changed, 52 insertions(+), 57 deletions(-) diff --git a/app/manifest.json b/app/manifest.json index e51074c..30a9d34 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -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 } \ No newline at end of file diff --git a/app/scripts/app/app.ts b/app/scripts/app/app.ts index d4d4f7d..40a257f 100644 --- a/app/scripts/app/app.ts +++ b/app/scripts/app/app.ts @@ -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); } diff --git a/app/scripts/inject/levelup.common.utility.ts b/app/scripts/inject/levelup.common.utility.ts index c90a5bb..7d175c8 100644 --- a/app/scripts/inject/levelup.common.utility.ts +++ b/app/scripts/inject/levelup.common.utility.ts @@ -40,7 +40,7 @@ module LevelUp { return this._version; } - fetch(entityName: string, attributes?: string, filter?: string): Promise> { + fetch(entityName: string, attributes?: string, filter?: string, id?: string, fetchXML?: string): Promise> { let headers = new Headers({ "Accept": "application/json", "Content-Type": "application/json; charset=utf-8", @@ -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, diff --git a/app/scripts/inject/levelup.forms.ts b/app/scripts/inject/levelup.forms.ts index a69b052..1eaeb21 100644 --- a/app/scripts/inject/levelup.forms.ts +++ b/app/scripts/inject/levelup.forms.ts @@ -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() { diff --git a/app/scripts/inject/levelup.servicecalls.ts b/app/scripts/inject/levelup.servicecalls.ts index a499010..791095f 100644 --- a/app/scripts/inject/levelup.servicecalls.ts +++ b/app/scripts/inject/levelup.servicecalls.ts @@ -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, ` - + + + + - + - - - - `), - 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(); + `).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, @@ -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'); diff --git a/package-lock.json b/package-lock.json index 8bafbf3..85b1b7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Levelup-for-Dynamics-CRM-365", - "version": "3.3.0", + "version": "3.3.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -58,9 +58,10 @@ "dev": true }, "@types/xrm": { - "version": "8.2.5", - "resolved": "https://registry.npmjs.org/@types/xrm/-/xrm-8.2.5.tgz", - "integrity": "sha1-KZ77+aKrzAKqA50cXbg7AMuh3gU=" + "version": "9.0.14", + "resolved": "https://registry.npmjs.org/@types/xrm/-/xrm-9.0.14.tgz", + "integrity": "sha512-JRqIt7BoXNDjWJLZF1MCcWMCLP+N9+pTrsh8maPXxmGW49BmpTOSWQT3tPgK8l6YUPWFpDdrWEkAfbQO4bAMEg==", + "dev": true }, "abbrev": { "version": "1.1.1", diff --git a/package.json b/package.json index 354c213..0ae5908 100644 --- a/package.json +++ b/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", @@ -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", @@ -62,7 +63,5 @@ "typescript": "^2.8.3", "webpack2": "^3.11.1" }, - "dependencies": { - "@types/xrm": "^8.2.5" - } + "dependencies": {} }