2

I am having trouble inserting new record in "Clients" list on our server, I am in learning phase for working with SharePoint Lists Web Services and I am trying to insert a new item in a list which contains ID of another list item.

Following is my code for setting lookup column value before sending data to webservice.

batch.InnerXml = "<Method ID='1' Cmd='New'>"
                + "<Field Name='" + Constants.Client_Field_FirstName + "'>" + clientObj.FirstNameOfIndividual + "</Field>"
                + "<Field Name='" + Constants.Client_Field_MiddleInitial + "'>" + clientObj.MiddleNameOfIndividual + "</Field>"                    
                //Save parent  id's
                + "<Field Name='" + Constants.CLIENT_FIELD_PARENT_ID + "'>" +  string.Format("{0};#", clientObj.ParentCaregiver1ID) + "</Field>"
                + "<Field Name='" + Constants.CLIENT_FIELD_PARENT_ID + "'>" + string.Format("{0};#", clientObj.ParentCaregiver2ID) + "</Field>"
                + "</Method>"; 

Basically I want Parent 1 and Parent 2 ID's to be inserted for new client. I don't know what is missing here. Client is added to the list and there is no error message but Parent ID's are blank.

Am I using right format for inserting lookup column value?

Please help.

4

If Constants.CLIENT_FIELD_PARENT_ID is the name of a multivalue lookup column then the value for that should be in the format Id1;#Value1;#Id2;#Value2 or without values Id1;#;#Id2;#

Which will give this code

batch.InnerXml = "<Method ID='1' Cmd='New'>"
                + "<Field Name='" + Constants.Client_Field_FirstName + "'>" + clientObj.FirstNameOfIndividual + "</Field>"
                + "<Field Name='" + Constants.Client_Field_MiddleInitial + "'>" + clientObj.MiddleNameOfIndividual + "</Field>"                    
                //Save parent  id's
                + "<Field Name='" + Constants.CLIENT_FIELD_PARENT_ID + "'>" +  string.Format("{0};#;#{1};#", clientObj.ParentCaregiver1ID, clientObj.ParentCaregiver2ID) + "</Field>"
                + "</Method>"; 

See Updating Multi Value Fields Using Web Service Call And Batch Update

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.