1

I want to check to see if a field exists in my program, but If I use :

if (item[_strContainingFieldName] != null)
{
    item[_strContainingFieldName] = fieldValue;
}

I receive an error stating

The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

So I wanted to use List.Fields.ContainsField or properties.ListItem.Fields.ContainsField but forgot I can only use these in the server API.

Is there something similar which I can make use of right now? The tool will be a "throw away" application since we're making updates behind the scenes, so I'm not too worried about catching every possibility and logging everything.

Note: The language is C#

  • What language are you writing the script in? – Brandon C. Jun 5 '14 at 14:44
  • C#. I tried to put it as a tag and it wouldn't accept it. Sorry! – Dinerdo Jun 5 '14 at 15:14
5

From the error i think you are using CSOM. If yes, then you have to load the properties before using it.

context.Load(item); 
context.ExecuteQuery();

To check if field exists use following:

if(item.FieldValues.ContainsKey("salesdate"))
  • I did this, so my updates to fields which exist are fine. But when I enter a field that doesn't exist, I want it to be skipped (so I users enter a field that is nonexistent, it should be skipped). – Dinerdo Jun 5 '14 at 15:15
  • 1
    you can check as if(item.FieldValues.ContainsKey("salesdate")) – Aanchal Jun 5 '14 at 15:20
  • Thanks! Can you add this comment to your answer? I will mark it accordingly. – Dinerdo Jun 5 '14 at 16:07
  • updated the answer. – Aanchal Jun 6 '14 at 5:15

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.