Articles about European Sharepoint Hosting Service
Sharepoint 2013 Hosting – HostForLIFE.eu :: Retrieve SP List Item’s Column Value In SPFx Application Customizer Using PNP
In this blog article, I am going to describe all the steps required to get SharePoint list field values by using SharePoint Framework model which is SPFx.
If you are already familiar with SPFx then you might have a better understanding on SPFx application customizer.
https://docs.microsoft.com/en-us/sharepoint/dev/spfx/sharepoint-framework-overview
In this below-mentioned code example, I have taken application customizer of SPFx. I have also used PnP JavaScript library. The Patterns and Practices JavaScript Core Library was created to help developers by simplifying common operations within SharePoint and the SharePoint Framework.
This below-mentioned code example is very simple and straight forward. At first, you have to import ‘sp-pnp-js’ namespace, then you can use PnP library in code to retrieve SharePoint list and its field values.
This code snippet will help you to retrieve any column values of all list items present under a particular list. You just have to provide your list title and list field/column internal name in the following line,
In the above piece of code “My list” is SP list title and “Title”, “Id”, “CustomField_1”, “CustomField_2” are list field/column internal names.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import { override } from '@microsoft/decorators'; import { Log } from '@microsoft/sp-core-library'; import { BaseApplicationCustomizer } from '@microsoft/sp-application-base'; import { Dialog } from '@microsoft/sp-dialog'; require('mutationobserver-shim'); import * as strings from 'HelloWorldApplicationCustomizerStrings'; const LOG_SOURCE: string = 'HelloWorldApplicationCustomizer'; /** * If your command set uses the ClientSideComponentProperties JSON input, * it will be deserialized into the BaseExtension.properties object. * You can define an interface to describe it. */ export interface IHelloWorldApplicationCustomizerProperties { // This is an example; replace with your own property testMessage: string; } let _observer: MutationObserver; /** A Custom Action which can be run during execution of a Client Side Application */ export default class HelloWorldApplicationCustomizer extends BaseApplicationCustomizer < IHelloWorldApplicationCustomizerProperties > { @override public onInit(): Promise < void > { Log.info(LOG_SOURCE, `Initialized ${strings.Title}`); let message: string = this.properties.testMessage; if (!message) { message = '(No properties were provided.)'; } this.context.placeholderProvider.changedEvent.add(this, this.renderObserver); return Promise.resolve(); } private async renderObserver(): Promise < void > { if (!_observer) { // Register observable let config = { childList: true, subtree: true }; _observer = new MutationObserver(this.addMyCustomMenu); _observer.observe(document, config); } } private addMyCustomMenu(mutationsList) { var o365Menus = document.querySelectorAll("*[class^=\"o365cs-mfp-linklist o365cs-segoeRegular o365cs-text-align-left\"]"); if (o365Menus.length > 0) { for (var i in o365Menus) { try { var menuItem = o365Menus[i]; var innerhtml = menuItem.innerHTML; var newhtml = '<div class="ms-fcl-tp o365cs-nfd-normal-lineheight"><a class="ms-fcl-tp o365button" role="link"'; newhtml += 'href="javascript:alert(\"Hello\");" id="O365_SubLink_CustomMenu"'; newhtml += 'aria-labelledby="_ariaId_9"><span class="_fc_3 owaimg" style="display: none;"></span>'; newhtml += '<span class="_fc_4 o365buttonLabel" id="_ariaId_9">My Custom Menu</span></a></div>'; menuItem.innerHTML = innerhtml.concat(newhtml); } catch (e) {} } } } private _onDispose(): void { if (_observer) { _observer.disconnect(); } console.log('[HelloWorldApplicationCustomizer._onDispose] Disposed custom.'); } } |
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options
Print article | This entry was posted by Peter on January 17, 2019 at 5:24 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |