2

I have a Employee list that contains 2 lookup fields (dept and manager). How do I get the ID for the manager lookup field?

                    FieldLookupValue mgrItem = new FieldLookupValue();                       
                    mgrItem.LookupId = Convert.ToInt32(department); //giving department throws an error like "input string was not in correct format"
                    item["Manager"] = mgrItem;

So what should be the ID that I should provide?

Kindly help! Thanks :)

  • 1
    are you sure that department is returning a valid string that can be converted to int? e.g you should have it "5" – Nderon Hyseni Aug 16 '17 at 11:40
  • Well when I tried out with "1", it changes to the first item present in the list. @NderonHyseni – Sanjana V Aug 16 '17 at 11:42
  • 1
    it seems that department is not a string that can be converted to int – Nderon Hyseni Aug 16 '17 at 11:45
3

try this one with department.

department = department.split('#')[1];
mgrItem.LookupId = Convert.ToInt32(department);
item["Manager"] = mgrItem;
  • Using this gives an error like "Index was outside the bounds of the array. " @NderonHyseni – Sanjana V Aug 17 '17 at 4:18

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.