Showing posts with label SharePoint Online. Show all posts
Showing posts with label SharePoint Online. Show all posts

Wednesday 20 December 2023

SharePoint site theme: Add a custom theme using PowerShell

In this blog, we will be learning how to create a custom theme for SharePoint Online.

Now SharePoint has a Site theming feature for applying custom styles and colors to the site. There are six light and two dark themes available by default. This feature provides the ability to define custom themes and make them available to site owners. Creating a custom theme in SharePoint is a quick and easy way to give your site a unique look and feel.

Currently, no theme is available under the "From your organization" option.


The steps to add a custom theme to SharePoint Online.

Step 1: Create a new color theme in SharePoint Online.

Themes are defined in a JSON schema that stores color settings and related metadata for each theme. Create a new custom theme for SharePoint Online using Microsoft Fluent UI Theme Designer, an online tool. Customize the theme as per your needs and click on the Export theme button. Copy and save the PowerShell output for later use.

Light Theme sample:


Dark Theme sample:


Step 2: Add a custom theme to SharePoint Online using PowerShell

First, connect to the SPO admin site using the Connect-SPOService cmdlet. The custom theme can be added to the SharePoint online tenant using the Add-SPOTheme cmdlet. This cmdlet creates a new theme or updates an existing theme. The color palette settings can be passed as either a hash table or a dictionary.

Execute the command for the light theme.



Now go to Site Settings, gear icon (⚙️) > Change the look > Theme and you'll find the newly added color theme listed under "From your organization".


Execute the same command for the dark theme.


Again, go to Site Settings gear icon (⚙️) > Change the look > Theme and you'll find the new added color theme listed under "From your organization".


When you choose a theme, color settings are instantly applied to the site so that you can see what the selected theme will look like. Select the desired theme, click Save to save your selection, or choose Cancel to revert to your current theme.

Our "Maroon - Light theme" output looks like




Our "Orange - Dark theme" output looks like




Update SP Theme
To update an existing theme (to modify some of its color settings, for example), add the -Overwrite flag to the Add-SPOTheme cmdlet.


I hope this will help all of you! 🧲
Feel free to provide feedback.


πŸš€ "Happy Coding" πŸš€

Wednesday 6 December 2023

Create List templates using Site template and Site script

In this blog, we will be learning how to create list templates under the tab From your organization.

When people in the organization create new lists, they need a template that can be used each time a new list is created.

Site Script

A site script is a collection of actions that SharePoint runs when creating a new site or list. Actions describe changes to apply to the new list, such as creating new columns, adding views, or content types. The actions are specified in a JSON script, which is a list of all actions to apply. When a script runs, SharePoint completes each action in the order listed.

Site Template (previously known as Site Design)

Site templates can be used each time a new site is created to apply a consistent set of actions. Site templates created using custom site scripts will display in the From your organization tab.

A site script is a JSON string that contains the actions to be taken on a site. A site template, on the other hand, is like a container for the site script. You can attach one or more site scripts to a site template, and when you apply the site template, you execute the actions defined in all of the site scripts. It's like the site template is the visible surface part that can group several site scripts together, and the site scripts are all the action underneath.

Currently, no list template is available From your organization tab.


  • A site template can run multiple scripts. The script IDs are passed in an array, and they run in the order listed.
  • The former term for site templates may still appear in certain cmdlets and script labels as "site design".
  • The schema is case-sensitive.

Create a Site script in JSON

Create the script in JSON that describes the action to be executed on the list. You can view and reference the latest JSON schema file here: https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json

In addition to constructing the JSON by hand, you can also use third-party tools with graphical user interfaces that generate the site scripts for you, such as sitedesigner.io by Mikko PunamΓ€ki or Site Template Studio by Yannick Plenevaux.

Exporting an existing list as a site script

In our scenario, we will be exporting an existing list configuration as a site script.
First, connect to the SPO admin site using the Connect-SPOService cmdlet. It can be achieved with the following script. The Get-SPOSiteScriptFromList cmdlet prints out the site script to the console. It can be saved into a variable, or you can copy and save it in a JSON file.


Deploy Site Script and Site Template

To use our site script, we need to deploy it to our tenant. We also need to create a site template where we can attach the deployed site script.

1) Add the site script

Each site script must be registered in SharePoint so that it is available to use. Add a new site script by using the Add-SPOSiteScript cmdlet.


After running the cmdlet, you get a result that lists the site script ID of the added script. Keep track of this ID, as it will be needed later when you create the site template.

2) Create the site template

Next, we will create the site template. Run the Add-SPOListDesign cmdlet to add a new site template. Use the script ID saved above when you added the site script. It can run one or more scripts that have already been added.


The JSON response displays the ID of the new site template. It can be used later on to update or modify the site template.

Get the existing Site Script and Site Template

After we have deployed our site script and site template to our tenant, we can see their properties and information about all other deployed site scripts and templates using the Get-SPOSiteScript and Get-SPOListDesign cmdlet.



Use the new site template

Now that we've added a site script and site template, we can use them to create a new list.



I hope this will help all of you! 🧲
Feel free to provide feedback.


πŸš€ "Happy Coding" πŸš€

Friday 14 July 2023

PowerApps: Set the default user value in the Canvas app.

I came across one of the tasks in PowerApps to set the default value of the Person Type column.

In this blog, we will be learning how to set the default value in the Canvas app.

Please follow the below steps:

1. Create a new SharePoint list.

2. Create a Person/User type column called "Requestor Name".


3. Create a blank Canvas App with Format Tablet.

4. Add an Edit form control on screen and add the above created list as the data source for this form control. Set form DefaultMode to New.

5. For "Requestor Name DataCard" set the below value for the Default property.

Switch(
    frm_FileTransferService.Mode,
    FormMode.New,
    {
        '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        DisplayName:User().FullName,
        Claims:"i:0#.f|membership|" & Lower(User().Email),
        Email:User().Email,
        Picture:User().Image
    },
    FormMode.View,
    ThisItem.'Requestor Name'
)


6. No need to do any changes in the Update property value. Its shown for reference only.


7. Under "Requestor Name DataCard" for DataCardValue.

    a. Comment on the Items property value, as it's not required. The items property is for populating the data in the people picker.


    b. Set the below value for the DisplayMode property. This DisplayMode property is used to configure whether the control inside the card allows user input (Edit), only displays data (View), or is disabled (Disabled).

If(
    frm_FileTransferService.Mode = FormMode.New,
    Parent.DisplayMode.Disabled,
    Parent.DisplayMode
)


9. Save and Publish the app.

10. Play/Run the app. In the New Form, the logged-in user is shown as default, and editing is disabled.



πŸš€ "Happy Coding" πŸš€

Sunday 2 January 2022

Power Automate: Update file metadata and preserve version history.

In this blog, we will be updating file properties/metadata whenever a new file is uploaded into the library.

In this approach, we will use the REST API and wrap it into a Power Automate flow.

Create Flow

Complete flow with all actions


Flow URL - https://flow.microsoft.com/

1. Open the flow, click on the Create option, and select "Automated Cloud Flow".


Enter Flow name.
Choose the flow trigger as "When an item is created".
Click the Create button.



2. Enter the "Site Address" SharePoint site URL and the "List Name" library title where flow needs to be associated.

Add a new action step, "Compose" and rename it "Compose-user".

In input, add an object as shown below. Created By Claims is value; here we will get the claims value of the user who is uploading the file.



3. Add a new action step again, "Compose" and rename it as "Compose-update".

In input, add an object as shown below.

  {

    "FieldName": "Internal column name",

    "FieldValue": "desired value"

  },

  {

    ............

  },

  .....

]

The input value will be an array of objects, and each object defines the configuration of the column to be updated. The FieldName is the internal column name, and the FieldValue is the desired value that you want to set in that column.

In my example, the Editor (Modified by) and Title columns are updated.

In the Editor FieldValue output of Compose-user will be set.

Note: Flow is running under the service account. If the Editor field is updated, then we can also preserve the Modified By column. Otherwise, the service account value will be updated in the Modified By column.



4. Add a new action step: Send an HTTP request to SharePoint.

Here we will compose a REST API request call.

  • Site Address: SharePoint site URL where the library is present
  • Method: POST
  • Uri: _api/web/lists/getbytitle('<List Title>')/items(<ID>)/validateUpdateListItem
  • Body: 

{
   "formValues": outputs('Compose_-_update'),
   "bNewDocumentUpdate":true
}


        validateUpdateListItem: REST API ValidateUpdateListItem() function to update listitem metadata

        formValues: The value must be the output of the second Compose action.

        bNewDocumentUpdate: true (Not to create any version on update) or false (Create a version on the update)

        For details refer: https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj246412(v=office.15)



        Upload the file to the Documents library and test the flow.


        πŸš€ "Happy Coding" πŸš€

        Saturday 24 July 2021

        SharePoint Home site.

         In this blog, we will be discussing the SharePoint Home site.


        What is SharePoint Home site?

        SharePoint Home site is a Communication site. It is the main landing/home site for your modern SharePoint intranet portal. It brings together news, documents, events, content, conversations, feeds, videos, and other resources.


        How to set the site as Home site?

        1. Create a new site or use an existing Communication site.

        2. Open SharePoint Online Management Shell in administrative mode and connect to SharePoint as a global admin or SharePoint admin.

        Here I have installed Microsoft.Online.SharePoint.PowerShell modules.

        SharePoint Online Management Shell: Getting Started

        3. Run the below command:

        Set-SPOHomeSite -HomeSiteUrl https://developer5.sharepoint.com/sites/TheLanding

        It will take some time to reflect on the change. In my case, it took 20 minutes. Run the below command to check which site is currently set as the Home site.

        Get-SPOHomeSite

        Home site can also be set easily through the SharePoint Online admin center.


        Go to SharePoint Online admin center at https://YourDomain-admin.sharepoint.com

        1. Click on the Settings option.

        2. Click on the "Home site" link.

        3. Enter the URL of the SharePoint Online communication site that you would like to set as a home site.

        4. Press the Save button.


        ~~~ Things to know ~~~

        1. Only PowerShell is available to set a site as the Home site. Currently, it cannot be done through UI as of now.

        Update: Home site can be set easily through the SharePoint Online admin center.

        2. Only one site can be set as the Home site for a Tenant.

        Update: In the latest release, users will be able to set up multiple home sites by using multiple Viva Connections experiences. The feature is currently in private preview and is expected to start rolling out broadly by the end of July 2023.

        3. Home site (Communication site) search scope will now be tenant-wide. The default search scope is at the site level only.



        4. Home site can be a Hub site also.

        5. News coming from the Home site will have a distinguishing highlighted Home site name banner.



        The same is available in the SharePoint mobile app.

        6. Enables quick access (Home icon) to the Home site from the SharePoint mobile app.


        7. The Global Navigation option will be enabled for the Home site now.


        Remove site as Home site

        Run the below command to remove the site as your Home site.

        Remove-SPOHomeSite
        Update: Home site can be removed easily through the SharePoint admin center.

        πŸš€ "Happy Coding" πŸš€

        Sunday 4 July 2021

        SharePoint Online Management Shell: Getting Started

        In this blog, we will be discussing SharePoint Online Management Shell. The introduction, installation, and some example commands.


        Introduction

        SharePoint Online Management Shell is a tool that contains a Windows PowerShell module that allows administrators to manage their SharePoint Online subscription in Office 365 using PowerShell.

        SharePoint administrators can manage Sites, Users, Tenants and etc. Some of the tasks can be performed in the Microsoft 365 admin center, but not all operations are possible. Command-line operations in Windows PowerShell are composed of a series of commands. We can perform read, write, and execute command-line operations, and they are easier in PowerShell.


        Installation

        SharePoint Online Management Shell is not present out-of-the-box on the Windows operating system. You need to install the SharePoint Online Management Shell and connect to SharePoint Online.

        There are two options:

        1. Download and install the SharePoint Online Management Shell .msi package.


        2. Install the module from the PowerShell Gallery


        Open Windows PowerShell (or CMD) in administrative mode and install the SharePoint Online Management Shell by running the below command:

        Install-Module -Name Microsoft.Online.SharePoint.PowerShell
        

        Once the module is installed, execute the below command in administrative mode to check its details:
        Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version
        

        To update the SharePoint Online Management Shell, run the below command in administrative mode:
        Update-Module -Name Microsoft.Online.SharePoint.PowerShell
        

        To uninstall the SharePoint Online Management Shell, run the below command in administrative mode:
        Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell
        


        Run the below command to connect with the SharePoint Online admin center. Enter the SharePoint admin account credentials in the request dialogue box.

        Connect-SPOService -Url https://developer5-admin.sharepoint.com
        




        To disconnect and close the connection, run the below command:

        Disconnect-SPOService -Url https://developer5-admin.sharepoint.com


        πŸš€ "Happy Coding" πŸš€

        Tuesday 19 November 2019

        Export PDF in Power Apps and Power Automate (MS Flows): Approach 1

        In this blog, we will be exporting the List Item details into the PDF document with a button click. This approach is based on the use of both PowerApps and PowerAutomate.

        In this scenario, a customized PowerApps form is there that is used to display data coming from the SharePoint list, and a button will be present on click of which users can export content into the PDF.

        Create Flow

        Complete flow with all actions


        1. Open the flow, click on the Create option, search for "PowerApps", and select the option "PowerApps button" which triggers the flow on button click.


        2. Add the "Initialize variable" action.
        Enter the required values: – Name, Type and Value. To initialize the value, click on "See more".

        Now click on the option "Ask in PowerApps"; it means the value will come from PowerApps form when flow is called as a parameter.

        Select and add the initialized values. Similarly, create a new variable. Filename and initialize.

        Now create the FileFullname variable. To initialize the value, select the Expression tab and concatenate the value of the filename variable with the .html file extension.

        Similarly, create a new variable, CurrentUser and initialize.

        3. Add "Create File" (OneDrive for Business) action.
        Click on the Folder icon present in the Folder Path textbox. Browse the library and select the folder under which the HTML file will be saved and later converted to PDF.

        Set the variables initialized above for File Name and File Content.

        4. Add the "Create file using path" (OneDrive for Business) action.
        Click inside the File Path textbox, and a callout will open. Select Path value from the Create file in OneDrive group under Dynamic content. Set PDF as the Target type.
        Note: Create file OneDrive is the previous action, and these are all the outputs of it.

        5. Add the "Send an email (V2)" (Office 365 Outlook) action.
        Provide the required value for this as shown below.


        Modify PowerApps Form

        1. Open the list where Export PDF functionality needs to be implemented. Click on "Customize forms" to open PowerApps.

        2. Add a new screen and add an HTML text control to it.

        3. Add the HTML content with dynamic values as shown. The content will be added in double quotes.


        4. Add a button for "Export to PDF" functionality. On the button, attach the flow.
            a. Select the button.
            b. On the Action tab, select Flows.
            c. All available flows will appear; select the required one.
            d. Choose the "OnSelect" option to RUN the flow and pass the required parameters.
            e. Save and Publish the PowerApps.

        5. Open the display form and click on the "Export PDF" button.

        6. The exported PDF will be sent to the current logged-in user's email..

        Check the final exported PDF here


        πŸš€ "Happy Coding" πŸš€