Forum Discussion

andreagx's avatar
andreagx
Copper Contributor
May 20, 2023
Solved

SharePoint Online List: complete automatically the last field when insert "New item"

Hello, 

I would like to complete automatically the last field when insert "New item" like a kind of calcualted flield.
i.e: 

Field "Code SL" should be: first 3 char on "Profumo" + "Form". 
The field "Code SL" should be filled based on previus entry (fields in New item form) before Save, so the value LAV12 is the "calculated" value form previous fields. 

  • andreagx you don't need to do it with anything complicated like a Powershell script, it is very easy with the built-in functionality. Make your form a Power Apps customised form as in the image below where the Profumo column in the list is a choice column and so is the Form column. The Code column just needs to be single line of text. In the form I've renamed the fields to dataProfumo and dataForm respectively. Then in your code field change the default property from Parent.Default to Left(dataProfumo.Selected.Value,3)&dataForm.Selected.Value

     

    If you don't want your users to change the code then set the DisplayMode of the dataCode field to View.

     

    You can see it working on the attached video.

     

    Rob
    Los Gallardos
    Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

     

4 Replies

  • RobElliott's avatar
    RobElliott
    Silver Contributor

    andreagx you don't need to do it with anything complicated like a Powershell script, it is very easy with the built-in functionality. Make your form a Power Apps customised form as in the image below where the Profumo column in the list is a choice column and so is the Form column. The Code column just needs to be single line of text. In the form I've renamed the fields to dataProfumo and dataForm respectively. Then in your code field change the default property from Parent.Default to Left(dataProfumo.Selected.Value,3)&dataForm.Selected.Value

     

    If you don't want your users to change the code then set the DisplayMode of the dataCode field to View.

     

    You can see it working on the attached video.

     

    Rob
    Los Gallardos
    Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

     

    • andreagx's avatar
      andreagx
      Copper Contributor

      RobElliott 

      Thank you BRO!
      Is exactly that I mean!

       

      Now when the "Code" exist in the list Power Apps return an error not user frendly 🙂
      SharePoint default form said something like the item exist ..
      We can change this error returned by Power Apps form in something other?
      "Network error when using Patch function: The requested operation is invalid." is not so attributable about "the item already exists"

       

  • leo-claireity's avatar
    leo-claireity
    Copper Contributor

    andreagx I'm not sure I understood exactly what you needed correctly, so forgive me if I'm making any wrong assumptions, but you can achieve what you described using the following powershell script:

    # Import SharePoint PS module
    Import-Module Microsoft.SharePoint.PowerShell
    
    # Set variables
    $webUrl = "http://YourSharePointSiteURL"
    $listName = "Your List Name"
    
    # Get Web and List
    $web = Get-SPWeb $webUrl
    $list = $web.Lists[$listName]
    
    # Iterate through each item in the list
    foreach ($item in $list.Items) {
        # Get the values of the Profumo and Form fields
        $profumo = $item["Profumo"]
        $form = $item["Form"]
    
        # Calculate the new value for the Code SL field
        $codeSL = $profumo.Substring(0, 3) + $form
    
        # Update the Code SL field
        $item["Code SL"] = $codeSL
        $item.Update()
    }
    
    # Dispose of the SPWeb object
    $web.Dispose()
    • andreagx's avatar
      andreagx
      Copper Contributor

      Hello,
      thank you for your reply.
      A script is not applicable is my scenario (SharePoint Online). I need to automalically get the value from previous filelds during the "New Item" and when "New Item" form is still open and before saving data.

       

      I think we have to modify and manage the form in Power Apps 

Resources