The Stack Overflow podcast is back! Listen to an interview with our new CEO.
2 Code typo
source | link

There are at least 3 ways that you could go about doing this and it will depend mostly on what your business users feel comfortable with and what you feel comfortable with as the person creating the solution.

  1. Add a text field to your list that is hidden in the NewForm.aspx and use PowerShell running as a scheduled task (every 5 minutes or so) to fill in the field of new items that do not have a value for this field. Here is some example code. Let's assume that your list is called "Orders" and that the custom field you have added is called OrderNumber

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$gc = start-spassignment
$web = ($gc | Get-SPWeb http://portal.somedomain.com);
$ordersList = $web.Lists["Orders"];

$spQuery = New-Object Microsoft.SharePoint.SPQuery;
$spQuery.Query = "<Where><IsNull><FieldRef Name='OrderNumber' /></IsNull></Where>";
$orders = $ordersList.GetItems($spQuery);

foreach($order in $orders)
{
   #If you want to continue the same number scheme, add the last value used by your
   # previous system to the item's ID. If not, just use the ID in the format method.
   $orderNumericValue = $order.ID + 350;
   $order["OrderNumber"] = [String]::Format("PRJ{0:0000}", $orderNumericValue);
   $order.Update();
}

$gc | stop-assignmentspassignment
  1. Use a SharePoint designer workflow to fill in the field. I won't go into much detail here as this solution is well documented on the web.

  2. Use an ItemAdded Event Receiver. This, IMO, is the best option.

public override void ItemAdded(SPItemEventProperties properties)
{
   base.ItemAdded(properties);
   //Get a new handle on the list item.
   SPListItem item = properties.List.GetItemById(properties.ListItemId);
   item["OrderNumber"] = String.Format("PRJ{0:0000}", item.ID);
   item.Update();
}

There are at least 3 ways that you could go about doing this and it will depend mostly on what your business users feel comfortable with and what you feel comfortable with as the person creating the solution.

  1. Add a text field to your list that is hidden in the NewForm.aspx and use PowerShell running as a scheduled task (every 5 minutes or so) to fill in the field of new items that do not have a value for this field. Here is some example code. Let's assume that your list is called "Orders" and that the custom field you have added is called OrderNumber

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$gc = start-spassignment
$web = ($gc | Get-SPWeb http://portal.somedomain.com);
$ordersList = $web.Lists["Orders"];

$spQuery = New-Object Microsoft.SharePoint.SPQuery;
$spQuery.Query = "<Where><IsNull><FieldRef Name='OrderNumber' /></IsNull></Where>";
$orders = $ordersList.GetItems($spQuery);

foreach($order in $orders)
{
   #If you want to continue the same number scheme, add the last value used by your
   # previous system to the item's ID. If not, just use the ID in the format method.
   $orderNumericValue = $order.ID + 350;
   $order["OrderNumber"] = [String]::Format("PRJ{0:0000}", $orderNumericValue);
   $order.Update();
}

$gc | stop-assignment
  1. Use a SharePoint designer workflow to fill in the field. I won't go into much detail here as this solution is well documented on the web.

  2. Use an ItemAdded Event Receiver. This, IMO, is the best option.

public override void ItemAdded(SPItemEventProperties properties)
{
   base.ItemAdded(properties);
   //Get a new handle on the list item.
   SPListItem item = properties.List.GetItemById(properties.ListItemId);
   item["OrderNumber"] = String.Format("PRJ{0:0000}", item.ID);
   item.Update();
}

There are at least 3 ways that you could go about doing this and it will depend mostly on what your business users feel comfortable with and what you feel comfortable with as the person creating the solution.

  1. Add a text field to your list that is hidden in the NewForm.aspx and use PowerShell running as a scheduled task (every 5 minutes or so) to fill in the field of new items that do not have a value for this field. Here is some example code. Let's assume that your list is called "Orders" and that the custom field you have added is called OrderNumber

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$gc = start-spassignment
$web = ($gc | Get-SPWeb http://portal.somedomain.com);
$ordersList = $web.Lists["Orders"];

$spQuery = New-Object Microsoft.SharePoint.SPQuery;
$spQuery.Query = "<Where><IsNull><FieldRef Name='OrderNumber' /></IsNull></Where>";
$orders = $ordersList.GetItems($spQuery);

foreach($order in $orders)
{
   #If you want to continue the same number scheme, add the last value used by your
   # previous system to the item's ID. If not, just use the ID in the format method.
   $orderNumericValue = $order.ID + 350;
   $order["OrderNumber"] = [String]::Format("PRJ{0:0000}", $orderNumericValue);
   $order.Update();
}

$gc | stop-spassignment
  1. Use a SharePoint designer workflow to fill in the field. I won't go into much detail here as this solution is well documented on the web.

  2. Use an ItemAdded Event Receiver. This, IMO, is the best option.

public override void ItemAdded(SPItemEventProperties properties)
{
   base.ItemAdded(properties);
   //Get a new handle on the list item.
   SPListItem item = properties.List.GetItemById(properties.ListItemId);
   item["OrderNumber"] = String.Format("PRJ{0:0000}", item.ID);
   item.Update();
}
1
source | link

There are at least 3 ways that you could go about doing this and it will depend mostly on what your business users feel comfortable with and what you feel comfortable with as the person creating the solution.

  1. Add a text field to your list that is hidden in the NewForm.aspx and use PowerShell running as a scheduled task (every 5 minutes or so) to fill in the field of new items that do not have a value for this field. Here is some example code. Let's assume that your list is called "Orders" and that the custom field you have added is called OrderNumber

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$gc = start-spassignment
$web = ($gc | Get-SPWeb http://portal.somedomain.com);
$ordersList = $web.Lists["Orders"];

$spQuery = New-Object Microsoft.SharePoint.SPQuery;
$spQuery.Query = "<Where><IsNull><FieldRef Name='OrderNumber' /></IsNull></Where>";
$orders = $ordersList.GetItems($spQuery);

foreach($order in $orders)
{
   #If you want to continue the same number scheme, add the last value used by your
   # previous system to the item's ID. If not, just use the ID in the format method.
   $orderNumericValue = $order.ID + 350;
   $order["OrderNumber"] = [String]::Format("PRJ{0:0000}", $orderNumericValue);
   $order.Update();
}

$gc | stop-assignment
  1. Use a SharePoint designer workflow to fill in the field. I won't go into much detail here as this solution is well documented on the web.

  2. Use an ItemAdded Event Receiver. This, IMO, is the best option.

public override void ItemAdded(SPItemEventProperties properties)
{
   base.ItemAdded(properties);
   //Get a new handle on the list item.
   SPListItem item = properties.List.GetItemById(properties.ListItemId);
   item["OrderNumber"] = String.Format("PRJ{0:0000}", item.ID);
   item.Update();
}