0

I have a requirement to write a code that update an existing lookup field.

We are running sharepoint 2010. We have a content type, which is used throughout all the sites. The content type has a field called Product, which is a lookup field for all the products we have. The field also contains subproducts. For example, a product by name PR1000 has a subproduct PR1010 all in the same drop down menu.

Now we want to change this grouping and separate them based on product and subproduct. I have created new field called Parent Product (PP) and Child Product(CP).

I would like to programmatically update the Parent Product field with Product and Child PRoduct field with child product if any. So here is how it works; if an existing item or document has product PR1010, I would to update PP with PR1000 and CP with 1010.

The problem I am having in order to start this project is the product field is part of every document library and lists and there are 1000s of items with data for product.

Please help with ideas or suggestions. I am thinking of a feature event receiver, which when activated will automatically update every item with product field not empty.

Thanks for your help in advance.

0

For new items an Event Receiver can do the trick. You can use ItemUpdate event and then extract and update the product information.

For existing items you can use PowerShell to get all list and libraries. Then for each list or library get all items. Then for each item you can read the product detail and update the item.

Make sure to disable the event receiver while you run the PowerShell.

  • I am using powershell and it seems to be getting me in the right direction. One problem I am facing though is that the update to the new lookup is not working and I know why but can't figure out a better way to resolve it. When I am updating the new lookup list field with value from the old list because the ID or the position of the lookup values in the new list does not match the existing one it does not work. I have tried to strip off the ID;# from the old list values to update the existing but it does not update either. Can anyone please help? – kjoeandy Mar 25 '15 at 15:08
  • Have you updated the new items using item.Update()? Then only it will be come available. Also lookup should be stored in a different way. You can check in google. – Amal Hashim Mar 25 '15 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.