locked
Generate Auto number in specific format RRS feed

  • Question

  • Hi

    I have created a field in my sharepoint list cammed M#, this field will automatically be populated using the ID field of this list but in specific format.

    Format will be "M - " + [ID] where [ID] is the ID of that item.

    How can i do that,

    Best regards


    SharePoint 2007 (Administration/Development) | Web developer and .NET DTS Programmer | .NET Framework 2.0/3.5 | SQL Server 2008/2005/2k

    Tuesday, February 7, 2012 3:59 AM

Answers

  • hi aliusmankhan1,

    This behavior occurs because a security fix in Windows SharePoint Services 3.0 SP1 prevents declarative workflows from starting automatically under the system account. After you install Windows SharePoint Services 3.0 SP1, declarative workflows do not start automatically if the following conditions are true:
    The Windows SharePoint Services Web application runs under a user's domain account.
    The user logs in by using this domain account.
    The site displays the user name as System Account.

    To resolve this behavior, set the application pool account to use a different user account. You may want to create a new user account specifically for this purpose.

    To set the application pool account to use a different user account, follow these steps:
    On the server that is running one of the products that is listed in the "Applies to" section, click Start, point to All Programs, point to Microsoft Office Server, and then click SharePoint 3.0 Central Administration.
    Click the Operations tab.
    Under Security Configuration, click Service Accounts.
    Click Web application pool, and then click Windows SharePoint Services Web Application in the Web service box.
    In the Application pool box, click the application pool that you want to change.
    Under Select an account for this component, click Configurable, and then type the user name and the password for the different user account.

    you can refer to the following link.

    http://kbalertz.com/947284/declarative-workflow-start-automatically-after-install-Windows-SharePoint-Services-Service.aspx

    Thanks,

    Jack

    • Marked as answer by Mike Walsh FIN Tuesday, February 14, 2012 9:22 AM
    Friday, February 10, 2012 6:04 AM
    Moderator

All replies

  • A quick solution might be to create a workflow that fires on all "NEW" items and assigns the value of ID from the last item created.

    OR

    You could go for an event treceiver which fires on itemadded or updated and allows you to set the field value as desired.

    Note: Do not go for calculated field approach as the ID will not available while creation of an item

    Hope this helps!!


    My SharePoint Blog
    http://www.dhirendrayadav.com

    Tuesday, February 7, 2012 5:44 AM
  • Hey Yadav,

    Thats what i am already familier with, I am looking for a solution here please and most probably solution with a workflow rather then Event reciver/handler.

    I tried following solution but didnt work as i can not pick "Calculated Field" in my workflow (http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/867bcacd-d378-411a-849a-fc040de9e5da)

    It is correct that calculated field with [ID] is not working as you said SharePoint doesn't create OR reserve ID while item creation is still pendding until the ADD button is clicked. 

    For me, i guess there should be some thing in workflow which might can help getting what i want.

    Any help will be appriciated.


    SharePoint 2007 (Administration/Development) | Web developer and .NET DTS Programmer | .NET Framework 2.0/3.5 | SQL Server 2008/2005/2k

    Tuesday, February 7, 2012 5:53 AM
  • Why are you using a calculated field?? instead your field can be "single line of text" field and you update that with the required logic through a workflow

    My SharePoint Blog
    http://www.dhirendrayadav.com

    Tuesday, February 7, 2012 10:26 AM
  • Why are you using a calculated field??

    Hi

    How can i increment a Numeric field in workflow? and update the LIST ITEM


    SharePoint 2007 (Administration/Development) | Web developer and .NET DTS Programmer | .NET Framework 2.0/3.5 | SQL Server 2008/2005/2k



    • Edited by aliusman Wednesday, February 8, 2012 3:22 AM
    Wednesday, February 8, 2012 3:21 AM
  •  

    Hi aliusmankhan1,

    You can create auto number in specific format in event handler. Here I will give you the simple code.

    public class AutoNumberEventHandler : SPItemEventReceiver
    {
     
    public override void ItemAdded(SPItemEventProperties properties)
      {
        SPListItem item = properties.ListItem;          

        item["Item Number"] = DateTime.Now.ToString("yyyy") + "-" + item["ID"];
        item.Update();
       }
    }    

    Thanks,

    Jack

    Wednesday, February 8, 2012 5:56 AM
    Moderator
  •  you can create auto number in specific format in event handler. Here I will give you the simple code.

    hi jack,

    As i requested , i do not want to use Event handler, i want SPD solution

    Cheers


    SharePoint 2007 (Administration/Development) | Web developer and .NET DTS Programmer | .NET Framework 2.0/3.5 | SQL Server 2008/2005/2k

    Wednesday, February 8, 2012 6:44 AM
  •  

    Hi aliusmankhan1,

    If you don’t want to use the event handler, you can use other ways in SharePoint designer. After my search, I find an article is about it. You can refer to the following link.

    https://www.nothingbutsharepoint.com/sites/eusp/Pages/sharepoint-how-to-create-an-auto-incrementing-number-field-for-use-in-a-custom-id-part-1.aspx

    Thanks,

    Jack


    Wednesday, February 8, 2012 7:05 AM
    Moderator
  • Hi,

    Thats wha i did and its working fine except the problem is , Workflow doesn't start automatically.


    SharePoint 2007 (Administration/Development) | Web developer and .NET DTS Programmer | .NET Framework 2.0/3.5 | SQL Server 2008/2005/2k

    • Marked as answer by Jack-GaoModerator Friday, February 10, 2012 1:09 AM
    • Unmarked as answer by Jack-GaoModerator Friday, February 10, 2012 1:09 AM
    • Marked as answer by aliusman Tuesday, February 14, 2012 5:50 AM
    • Unmarked as answer by Mike Walsh FIN Tuesday, February 14, 2012 9:22 AM
    Friday, February 10, 2012 12:35 AM
  • Hi aliusmankhan1,

    Do you mean you can start the workflow manually? When you create a workflow, at the bottom of the box, there is some checkboxs, please check the checkbox. I list them here.

    Allow this workflow to be manually started from an item.

    Automatically start this workflow when a new item is created

    Automatically start this workflow whenever an item is changed

    If you are already have checked them, please check your action in your workflow, may be some errors in your action caused the workflow can’t start.


    Thanks,

    Jack


    Friday, February 10, 2012 1:10 AM
    Moderator
  • hey Jack

    1. Yes, All the boxes are checked in

    2. I click on "CHECK WORKFLOW" button and it shows no error.

    3. Also if workflow runs fine manually without any error so i asume it doesn't have any issues

    Not sure what to do to make it run automatically


    SharePoint 2007 (Administration/Development) | Web developer and .NET DTS Programmer | .NET Framework 2.0/3.5 | SQL Server 2008/2005/2k

    Friday, February 10, 2012 5:25 AM
  • hi aliusmankhan1,

    This behavior occurs because a security fix in Windows SharePoint Services 3.0 SP1 prevents declarative workflows from starting automatically under the system account. After you install Windows SharePoint Services 3.0 SP1, declarative workflows do not start automatically if the following conditions are true:
    The Windows SharePoint Services Web application runs under a user's domain account.
    The user logs in by using this domain account.
    The site displays the user name as System Account.

    To resolve this behavior, set the application pool account to use a different user account. You may want to create a new user account specifically for this purpose.

    To set the application pool account to use a different user account, follow these steps:
    On the server that is running one of the products that is listed in the "Applies to" section, click Start, point to All Programs, point to Microsoft Office Server, and then click SharePoint 3.0 Central Administration.
    Click the Operations tab.
    Under Security Configuration, click Service Accounts.
    Click Web application pool, and then click Windows SharePoint Services Web Application in the Web service box.
    In the Application pool box, click the application pool that you want to change.
    Under Select an account for this component, click Configurable, and then type the user name and the password for the different user account.

    you can refer to the following link.

    http://kbalertz.com/947284/declarative-workflow-start-automatically-after-install-Windows-SharePoint-Services-Service.aspx

    Thanks,

    Jack

    • Marked as answer by Mike Walsh FIN Tuesday, February 14, 2012 9:22 AM
    Friday, February 10, 2012 6:04 AM
    Moderator
  • > you can refer to the following link.

    http://kbalertz.com/947284/declarative-workflow-start-automatically-after-install-Windows-SharePoint-Services-Service.aspx

    Please use the original link to a Microsoft site when available. This is a Microsoft KB article and its source is at support.microsoft.com - KBAlertz is just grabbing the article in order to get people to see its adverts.

    http://support.microsoft.com/kb/947284/en-us is what should have been used here.


    SP 2010 "FAQ" (mainly useful links): http://wssv4faq.mindsharp.com/default.aspx
    WSS3/MOSS FAQ (FAQ and Links) http://wssv3faq.mindsharp.com/default.aspx
    Both also have links to extensive book lists and to (free) on-line chapters

    Friday, February 10, 2012 9:06 AM