import { getSP } from './pnp/pnpjs'; /** Инициатор заявки — из системного поля «Автор» (Created By) элемента списка. */ export interface IInitiator { name: string; email: string; } /** * Прочитать инициатора (создателя) элемента списка по его Id. * Источник — системное поле Author (Created By), заполняется SharePoint * автоматически при создании, работает для любой формы без доп. колонок. * Возвращает undefined, если элемент/автор недоступен (не роняем шапку). */ export async function getCreatedBy(listTitle: string, itemId: number): Promise { try { const item = (await getSP() .web.lists.getByTitle(listTitle) .items.getById(itemId) .select('Author/Title', 'Author/EMail') .expand('Author')()) as { Author?: { Title?: string; EMail?: string } }; const author = item.Author; if (!author) return undefined; return { name: author.Title || '', email: author.EMail || '' }; } catch { return undefined; } }