Forum Discussion
SharePoint Online List: complete automatically the last field when insert "New item"
- May 21, 2023
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 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()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