Answered How to:Prepopulation (auto fill in values) Based on Text Contained in the Document Name

  • Tuesday, April 03, 2012 6:06 AM
     
     

    This seems relatively simple, but I cannot think of a way to make the text query work. Basically, upon uploading of document(s) to a specific folder in a library, the document fields (which are also stored in a couple lists) are prepopulated and filled in.

    As an example: List X has columns: Legal Statute; Priority; Region

    The Legal Statute column has entries like AB_885_b and AB_886_b  etc.

    A document whos name contains (not exactly) the Legal Statute is uploaded (i.e. document name = ColorCodesAB_885_b_Draft 3_CreatorName) to a document library.

    The workflow should first search the name of the document, see that it contains the Legal Statute from the list, and then fill in columns from the list into the document Columns which are similar.

    It seems like it should be fairly easy, but maybe not. Any ideas out there? I am restircted to Sharepoint Designer 2007 and don't know any code of any kind. If possible, I'd like to stay away from making any forms unless I have to.

    Thank you in advance for your help!!!


    • Edited by Titikshu88 Tuesday, April 03, 2012 6:28 AM
    • Edited by Titikshu88 Tuesday, April 03, 2012 6:30 AM
    • Edited by Titikshu88 Wednesday, April 04, 2012 8:06 AM
    •  

All Replies

  • Wednesday, April 04, 2012 8:05 AM
     
     

    Nobody? Am I wording my question wrong or is it just too easy it's not worth anyone's time or what?

    I've created a temporary workflow for now that will automatically fill in the other values as long as a user selects one column's data. Workflows on Document Libraries seem to be a bit more difficult than Lists as the document check-in process messes some things up.

    At any rate, any ideas or input is much appreciated.

  • Thursday, April 05, 2012 6:59 AM
    Moderator
     
     
     

    Hi Titikshu88,

    I don't fully understand your meaning. So, the document name contains the “Legal Statute” , you will search if it is exists in your list, if exists, you will update your document library column with your custom list. If I misunderstood you please tell me feel free.

    So, you can do it like the following screen shot.

    Thanks,

    Jack

    • Proposed As Answer by Esad Ismailov Thursday, April 05, 2012 10:03 AM
    • Unproposed As Answer by Titikshu88 Thursday, April 05, 2012 11:05 AM
    •  
  • Thursday, April 05, 2012 11:05 AM
     
     

    Hello Jack Gao,

    So, I have a list on sharepoint (Legal List) that contains legal statutes and columns of information (Department, Contact Person, Color Coding, Division, Etc.)

    I also have a library for uploading documents pertaining to these legal statutes. The Column headings in the Document Library are Document Name, Legal Statute, Color Coding, and Division). Document names already have the specific legal statute they are for.

    Right now, when a user uploads a document, they need to select the legal statute from a drop down, and then select the department, and division, and contact person (which is already in the Legal List).

    What I'm looking for is a way a user can just upload the document and the other details will automatically be entered. Uploading document named "ST_001.1_John Doe_Version 5" would automatically find "ST_001.1" as the legal statute from the Legal List and automatically fill in the Color Coding and Division.

    I hope this is clearer and am very thankful for your help!

  • Friday, April 06, 2012 3:12 AM
    Moderator
     
     Answered Has Code

    Hi Titikshu88,

    Yes, I have known it with your description. When I have a try with SharePoint designer Workflow, I’m failure. So, I think the best way is use Event handler to achieve it. The following is my code.

    public override void ItemAdded(SPItemEventProperties properties)
            {
                SPListItem item = properties.ListItem;
                using (SPSite thisSite = new SPSite(properties.WebUrl))
                {
                    SPWeb thisWeb = thisSite.OpenWeb();
                    SPListItemCollection LegalListItems = thisWeb.Lists["LegalList"].Items;//here get all items from your Legal List
                    foreach (SPListItem ItemLegal in LegalListItems)
                    {
                        if (properties.AfterProperties["Name"].ToString().Contains(ItemLegal["LegalStatutes"].ToString()))
                        {
                            item["LegalStatutes"] = ItemLegal["LegalStatutes"];
                            item["Department"] = ItemLegal["Department"];
                            item["ContactPerson"] = ItemLegal["ContactPerson"];
                            item["ColorCoding"] = ItemLegal["ColorCoding"];
                            item["Division"] = ItemLegal["Division"];
                            item.Update();
                            thisWeb.Update();
                        }
                    }
                }
                
            }

    Thanks,

    Jack


  • Wednesday, April 11, 2012 8:52 AM
     
     

    Hey Jack,

    Thanks for the event handler. I'll be working on our Sharepoint environment in a couple days so I'll give it a shot, but it looks like this should do the trick. Thanks again for your help!