locked
Copy Metadata from document library to custom list

    Question

  • Hello,

    Does anyone know if it is possible to copy metadata column data from a document library record to a custom list?  So say I have a document library that I use to upload scanned invoices.  After uploading the invoice, I am prompted to enter in required invoice metadata such as [Vendor], [Inv No], [Inv Amt], [Due Date] for example.  I then have a custom list that I would like to use  to allow clients the ability to pay the invoice in full or in part.  The two columns in this list are [Amt to Pay], [Date to Pay].

    What I would like to do is to have all of the metadata columns from the library that Finance staff entered when the invoice scanned object was uploaded copy into the Custom Payments List when a new invoice is added.

    I did just try to do this through the use of a workflow but the workflow only wanted to copy the actual file and not the metadata.

    Any ideas?

    Thank you for your thoughts.

    Sincerely,

    Tim

    • Moved by Mike Walsh FIN Wednesday, March 24, 2010 5:09 AM not customization - asking for general guidance (From:SharePoint - Design and Customization (pre-SharePoint 2010))
    Tuesday, March 23, 2010 6:11 PM

Answers

  • If you are using an Invoice content type for your document library, I would just add that content type to the list.  Then use a workflow to manually copy each field over.

    Assuming the field is a string this is what your code might look like:

    newItem["Field"] = (string)sourceItem["Field"]

    newItem.Update();


    Kevin
    • Marked as answer by SPA-TMF Friday, March 26, 2010 1:38 PM
    Tuesday, March 23, 2010 6:32 PM
  • Hello,

    Does anyone know if it is possible to copy metadata column data from a document library record to a custom list? 

    Any ideas?

    Thank you for your thoughts.

    Sincerely,

    Tim


    Use Site Columns on ur Main site the the column is vissible for all Site, Library and more.
    • Marked as answer by SPA-TMF Friday, March 26, 2010 1:38 PM
    Thursday, March 25, 2010 10:57 AM

All replies

  • If you are using an Invoice content type for your document library, I would just add that content type to the list.  Then use a workflow to manually copy each field over.

    Assuming the field is a string this is what your code might look like:

    newItem["Field"] = (string)sourceItem["Field"]

    newItem.Update();


    Kevin
    • Marked as answer by SPA-TMF Friday, March 26, 2010 1:38 PM
    Tuesday, March 23, 2010 6:32 PM
  • using the OOTB copy item workflow activity won't work in your case, so you can do what Kevin suggested

    two additions on that:

    you can't use a content type based on the standard Document (or further derived) content type in a list (just in libraries), so you will need to create a mirror content type which inherits the standard Item 0x01 content type

    and second - you can iterate the fields of the content type and copy the values without it being necessary to cast the values - just copy them as objects:

    newItem["Field"] = sourceItem["Field"]

    Tuesday, March 23, 2010 6:41 PM
  • you can use an item added and item updated event receiver on you document library. and copy metadata field from doc lib to custom list ..use an custom field ,say itemID to map list record with doclib record's (ID field) e.g.

     

    SPListItem item = properties.ListItem;
    SPSite sitecoll = new SPSite(properties.SiteId);
    SPWeb site = sitecoll.OpenWeb(properties.RelativeWebUrl);
    site.AllowUnsafeUpdates = true;                
    SPList myList= site.Lists["your custom list"];
    SPQuery query = new SPQuery();
    query.Query = "<Where><Eq><FieldRef Name='ItemID'/><Value Type='Text'>" + item["ID"] + "</Value></Eq></Where>";
    SPListItemCollection itmcoll = myList.GetItems(query);
    if (itmcoll.Count >= 1)
    {
             SPListItem newitm = itmcoll[0];
             newitm["field 1"] = item["Field 1"];
             newitm["field 2"] = item["Field 2"];
             newitm["field 3"] = item["Field 3"];
             newitm.Update();
    }
    else
    {
             SPListItem newitm = lstException.Items.Add();
             newitm["field 1"] = item["Field 1"];
             newitm["field 2"] = item["Field 2"];
             newitm["field 3"] = item["Field 3"];
             newitm["ItemID"] = item["ID"].ToString();
             newitm.Update();

    }



    Thanks
    Ganesh Jat [My Blog | LinkedIn | Twitter ]
    Wednesday, March 24, 2010 6:42 AM
  • Thank you all for your replies and ideas!

    I was workikng on this last night and realized that I might be actually over-engneering this.  What I ended up with was a custom list (used to capture all of the metadata) and the attachment (to handle the upload of the scanned invoice).  In this way I am only dealing with one source for all information. 

    However, I am still presented with a similar problem in that if the invoice is only partially paid, then I want a new invoice line created that represents the remaining balance of the original invoice to be paid.

    So what I have is a column called [Invoice Amt] and a column called [Amount Paid] and a column called [Remaining Balance].  The remaining balance column is a calculated column that displays the difference between Invoice amount and Amount Paid.

    What I want is that if the original invoice is only partially paid, a new invoice line created that contains all of the data from the original invoice with one exception: [Invoice Amt] = [Remaining Balance].

    I know I can copy the current row into the list but how can I accomplish the above where I want the Invoice Amt to equal the Remaining balance?  I am going to pursue Kevins suggestion(s) but wonder if this is possible since the columns are currency columns...

    Thank you all again.

    Sincerely,

    Tim

    Wednesday, March 24, 2010 1:14 PM
  • Hello,

    I just figured out that I was addressing this the wrong way.  Instead of using the coyp function in SPD I should have been usng the Create function.  that gives me more control over individual columns of data and the ability to implement Kevins suggestion(s).

    Will update this post when complete.

    Thank you all again!

    Sincerely,

    Tim

    Wednesday, March 24, 2010 1:22 PM
  • Ok, so here is what I have:

    I was able to create a new lineitem for the invoice if the following conditions were met:

    1. If Invoice Amount > Amount to Pay and
    2. Amount to Pay > 0

    Then create new line.

    This produces the following result:

    As you can see above, the only field not copying over is the Invoice Number.  It is nothing more than a text field.  All other text fields copy just fine.

    Anyone have any thoughts as to why this is or how I can get the Invoice Number to copy into the new line (like the others)?

    Thank you for your help.

    Sincerely,

    Tim

    Wednesday, March 24, 2010 2:40 PM
  • Hello,

    Does anyone know if it is possible to copy metadata column data from a document library record to a custom list? 

    Any ideas?

    Thank you for your thoughts.

    Sincerely,

    Tim


    Use Site Columns on ur Main site the the column is vissible for all Site, Library and more.
    • Marked as answer by SPA-TMF Friday, March 26, 2010 1:38 PM
    Thursday, March 25, 2010 10:57 AM
  • So I was able to fix my issue(s) by creating a content type for this list.  Originally I had not and it appeared to be the source of my problem insofar as the InvID not copying was concerned.  Once I created the content type, the site columns and then the list by which I added the content type to, all of the workflows worked just fine.

    Thank you all for your help and comments.

    Sincerely,

    Tim

    Friday, March 26, 2010 1:38 PM