From 65ba2991afd8168c518cee934ad91c0ef32a29b3 Mon Sep 17 00:00:00 2001 From: Josef Benda Date: Mon, 19 Sep 2022 12:31:12 +0200 Subject: [PATCH 1/4] Removed parsing the user ID from default value, because the ID is no longer in the peoplePicker default value --- src/controls/dynamicForm/DynamicForm.tsx | 30 +++++++----------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index 9609e580d..6ddb67281 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -281,28 +281,16 @@ export class DynamicForm extends React.Component { - if (item.split('/')[1] === element.text) { - retrivedItem = true; - field.newValue.push(item.split('/')[0]); - } - }); - } - if (!retrivedItem) { - if (element.id === undefined || parseInt(element.id, 10).toString() === "NaN") { - let user: string = element.secondaryText; - if (user.indexOf('@') === -1) { - user = element.loginName; - } - const result = await sp.web.ensureUser(user); - field.newValue.push(result.data.Id); - } - else { - field.newValue.push(element.id); + if (element.id === undefined || parseInt(element.id, 10).toString() === "NaN") { + let user: string = element.secondaryText; + if (user.indexOf('@') === -1) { + user = element.loginName; } + const result = await sp.web.ensureUser(user); + field.newValue.push(result.data.Id); + } + else { + field.newValue.push(element.id); } } } From c130b75858aa021e833ea40e5ddbe37749cdb275 Mon Sep 17 00:00:00 2001 From: Josef Benda Date: Mon, 19 Sep 2022 12:35:04 +0200 Subject: [PATCH 2/4] changed the 2 methods so that they do what the name intends - they return the default value for the peoplepicker with the UPN and not the ID --- src/services/SPService.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/services/SPService.ts b/src/services/SPService.ts index 3ac9f7a88..bba31af61 100644 --- a/src/services/SPService.ts +++ b/src/services/SPService.ts @@ -575,7 +575,7 @@ export default class SPService implements ISPService { public async getUsersUPNFromFieldValue(listId: string, listItemId: number, fieldName: string, webUrl?: string): Promise { // eslint-disable-line @typescript-eslint/no-explicit-any try { const webAbsoluteUrl = !webUrl ? this._context.pageContext.web.absoluteUrl : webUrl; - const apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/items(${listItemId})?@listId=guid'${encodeURIComponent(listId)}'&$select=${fieldName}/Title,${fieldName}/Id&$expand=${fieldName}`; + const apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/items(${listItemId})?@listId=guid'${encodeURIComponent(listId)}'&$select=${fieldName}/Title,${fieldName}/Id,${fieldName}/Name&$expand=${fieldName}`; const data = await this._context.spHttpClient.get(apiUrl, SPHttpClient.configurations.v1); if (data.ok) { @@ -583,7 +583,8 @@ export default class SPService implements ISPService { if (result && result[fieldName]) { const emails = []; result[fieldName].forEach(element => { - emails.push(element.Id + "/" + element.Title); + const loginNameWithoutClaimsToken = element.Name.split("|").pop(); + emails.push(loginNameWithoutClaimsToken + "/" + element.Title); }); return emails; } @@ -605,7 +606,7 @@ export default class SPService implements ISPService { if (data.ok) { const results = await data.json(); if (results) { - return userId + "/" + results.Title; + return results.UserPrincipalName + "/" + results.Title; } } From a49f54bbb0a55377b530fa987b437df8b712edf4 Mon Sep 17 00:00:00 2001 From: Josef Benda Date: Sun, 2 Oct 2022 23:29:46 +0200 Subject: [PATCH 3/4] Get Single User Field the same way as the multiple users --- src/controls/dynamicForm/DynamicForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index 6ddb67281..f52396799 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -443,7 +443,7 @@ export class DynamicForm extends React.Component Date: Mon, 3 Oct 2022 12:31:47 +0200 Subject: [PATCH 4/4] rewrite getUserUPNById to getUserUPNFromFieldValue for single user values --- src/controls/dynamicForm/DynamicForm.tsx | 2 +- src/services/SPService.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/controls/dynamicForm/DynamicForm.tsx b/src/controls/dynamicForm/DynamicForm.tsx index f52396799..47831a0d2 100644 --- a/src/controls/dynamicForm/DynamicForm.tsx +++ b/src/controls/dynamicForm/DynamicForm.tsx @@ -443,7 +443,7 @@ export class DynamicForm extends React.Component { + public async getUserUPNFromFieldValue(listId: string, listItemId: number, fieldName: string, webUrl?: string): Promise { try { const webAbsoluteUrl = !webUrl ? this._context.pageContext.web.absoluteUrl : webUrl; - const apiUrl = `${webAbsoluteUrl}/_api/web/getuserbyid(${userId})?$select=UserPrincipalName,Title`; + const apiUrl = `${webAbsoluteUrl}/_api/web/lists(@listId)/items(${listItemId})?@listId=guid'${encodeURIComponent(listId)}'&$select=${fieldName}/Title,${fieldName}/Id,${fieldName}/Name&$expand=${fieldName}`; const data = await this._context.spHttpClient.get(apiUrl, SPHttpClient.configurations.v1); if (data.ok) { - const results = await data.json(); - if (results) { - return results.UserPrincipalName + "/" + results.Title; + const result = await data.json(); + if (result && result[fieldName]) { + const element = result[fieldName] + const loginNameWithoutClaimsToken = element.Name.split("|").pop(); + return loginNameWithoutClaimsToken + "/" + element.Title; } }