none
Add Items to List with BDC Column via Web Services

    Question

  • I really hope this is possible.  I am trying to add items to a list that have a BDC column as one of the fields.  Here is the code I am using in the Batch

    batchElement.InnerXml = "<Method ID='1' Cmd='New'>" +  
     
    "<Field Name='Title'>Hello World</Field>" +  
     
    "<Field Name='bdc'>BDCIdentifier</Field></Method>";  
    try 
     
    {  
     
    XmlNode ndReturn = listService.UpdateListItems(strListID, batchElement);  
     
    }  
     

    When this is run the field "Title" is updated just fine but the BDC column remains empty when I go to view the list.  I have tried using a couple different values for the bdc field name but nothing seems to work.  I tried using the Identifier value from the BDCFieldsResolver web service but that didn't work either.

    Any thoughts?

    Shane

    Thursday, December 04, 2008 7:19 PM

All replies

  • When you add a BDC column to a list, it adds a second, hidden field to the list.  It will have the name [BDCFieldInternalName]_ID.  In your case, the name of the field would be "bdc_ID".  This field needs to be populated with the ID of the entity.

    Because you can have a composite key in BDC, you need to encode the key with the EntityInstanceIDEncoder class in order for the BDC to be updated properly.

    Inside of the SharePoint context, you can simply reference the Microsoft.Office.Server.dll assembly and use the encoder class to encode and decode your IDs.

    Outside of the SharePoint context, your task a lot harder.  You can disassemble the class and rip out its code,or you could try copying the assembly and using it outside of the SharePoint object model (which may throw a SecurityPermission error).

    Thursday, December 04, 2008 10:25 PM
  • Brian,

    Thanks for your answer.  That is what I thought might be the issue so I modified things a bit but still no dice.  Here is my complete test code.

    Basically, I went hunting for this [BDCFieldInternalName]_ID that I keep seeing in posts and I found it in the ndListView XmlNode below.  It shows the Name of the ID field being dbo_x002e_SharepointCustomerSumm.  I thought, ok, I got the name of the field, now I just need this magic number that Microsoft generates.

    Microsoft surely would be nice enough to provide access to this magic number via web services?  BDCFieldsResolver seems to do EXACTLY what the EntityInstanceIDEncoder does.  I ran both in this code, set a breakpoint and compared the results that each output.  Exactly the same.  Ok, so now I am armed with the Name of the magic field, and the magic number.  Happy Days.

    The BusinessData field is called bdc and is a text field so seems I just throw the string value of the item in there.  Run it.  Still no BDC field in the list when I refresh the page.  Just a lonely Title.


    BDC.Lists listService = new SharepointListTest.BDC.Lists();  
     
    listService.Credentials = System.Net.CredentialCache.DefaultCredentials;  
     
    listService.Url = "http://testsite/bdc/_vti_bin/Lists.asmx";  
     
    System.Xml.XmlNode ndListView = listService.GetListAndView("bdc""");  
    string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;  
    string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;  
     
    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();  
    System.Xml.XmlElement batchElement = doc.CreateElement("Batch");  
    batchElement.SetAttribute("OnError""Continue");  
    batchElement.SetAttribute("ListVersion""1");  
    batchElement.SetAttribute("ViewName", strViewID);  
     
    String bdcID = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[]  {"207375961772" });  
                  
    BDCResolve.BDCFieldsResolver resolver = new SharepointListTest.BDCResolve.BDCFieldsResolver();  
     
    resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;  
     
    BDCResolve.ResolveResult result = resolver.Resolve("Customer Summary""dbo.SharepointCustomerSummaryReport""207375961772""macaddress");  
     
    batchElement.InnerXml = "<Method ID='1' Cmd='New'>" +  
    "<Field Name='Title'>TestItem2</Field>" +  
    "<Field Name='dbo_x002e_SharepointCustomerSumm'>" + result.Identifier.Value + "</Field>" +  
    "<Field Name='bdc' Type='BusinessData'>207375961772</Field></Method>";  
     
    try 
    {  
        XmlNode ndReturn = listService.UpdateListItems(strListID, batchElement);  
    }  
    catch (Exception ex)  
    {  
        throw (ex);  



    ndListView XmlNode
    <Field Type="BusinessData" DisplayName="bdc" Required="FALSE" ID="{9f31f92e-1aad-4852-aa2b-6ee00414d14e}" SourceID="{fc7d899e-d860-4e8b-980d-605beb0075b3}" StaticName="bdc" BaseRenderingType="Text" Name="bdc" ColName="nvarchar3" RowOrdinal="0" Version="5" Group="" SystemInstance="Customer Summary" Entity="dbo.SharepointCustomerSummaryReport" BdcField="macaddress" Profile="" HasActions="False" SecondaryFieldBdcNames="" RelatedField="dbo_x002e_SharepointCustomerSumm" SecondaryFieldWssNames="" RelatedFieldBDCField="" RelatedFieldWssStaticName="dbo_x002e_SharepointCustomerSumm" SecondaryFieldsWssStaticNames="" AddFieldOption="AddToDefaultContentType, AddFieldToDefaultView" /> 
     
    <Field Type="Text" DisplayName="dbo.SharepointCustomerSummaryReport_ID" Hidden="TRUE" ReadOnly="TRUE" BdcField="dbo.SharepointCustomerSummaryReport_ID" ID="{d79da88a-35c0-4060-b47a-065cb2887490}" SourceID="{fc7d899e-d860-4e8b-980d-605beb0075b3}" StaticName="dbo_x002e_SharepointCustomerSumm" Name="dbo_x002e_SharepointCustomerSumm" ColName="nvarchar4" RowOrdinal="0" Version="1" /> 



    Thanks again,
    Shane
    Friday, December 05, 2008 5:35 PM
  • Same problem here.

    I can add a new splistitem through the api but not through the webservice:

    this works:

     

    SPListItem newItem = bdcList.Items.Add();
    newItem[
    "Title"] = _txtItemTitle.Text;
    newItem[_txtBdcFieldName.Text] = _txtBdcFieldValue.Text;
    newItem[_txtBdcRelatedFieldName.Text] =_txtBdcRelatedFieldValue.Text;
    newItem.Update();

    has anyone resolved this problem already?

    Greetings

    Monday, February 22, 2010 11:45 AM
  • I think i have found the problem.

    The relatedfield is read only:

    <Field Type="Note" Hidden="TRUE" eadOnly="TRUE" BdcField="dbo.Account_ID" StaticName="dbo_x002e_Account_ID" Name="dbo_x002e_Account_ID" />
    So it is not filled through the webservice.

    So make this field read only=false through the API

    spfield.ReadOnlyField = field.ReadOnly;
    spfield.Update();
    Call the webservice:
    <Method ID="1" Cmd="New">
      <Field Name="ID">New</Field>
      <Field Name="Title">testitem</Field>
      <Field Name="Account">Account Display Value</Field>
      <Field Name="dbo_x002e_Account_ID">__bk090093003300660083004600160046003300d2002300830066001300d2004600460013001300d2002600460063001600d200030003005300030053006300260016000300530066001300</Field>
    </Method>
    dbo_x002e_Account_ID is filled with the encoded value of the "Primary key of this item in the database" / Identifier

    Greetings
    Higo
    Wednesday, February 24, 2010 3:26 PM
  • Good stuff Higo.   I will have to try this out when I have a moment.  This could open up some nice possibilities for many people.

    Shane

    Wednesday, February 24, 2010 5:09 PM
  • I think i have found the problem.

    The relatedfield is read only:

    <Field Type="Note" Hidden="TRUE" eadOnly="TRUE" BdcField="dbo.Account_ID" StaticName="dbo_x002e_Account_ID" Name="dbo_x002e_Account_ID" />
    
    
    So it is not filled through the webservice.

    etc.

    I tried this and it worked however the secondary fields do not automatically update (since there is no way to trigger that to occur) so it looks like that still needs to be done through the api.
    • Edited by Mike Walsh FIN Friday, February 26, 2010 5:24 PM don't use full quote it takes up too much screen space for nothing
    Friday, February 26, 2010 4:06 PM
  • Hi all,

    If something isn't available with the out of the box web services why not write your own web service that uses the object model and deploy that web service to SharePoint?

    Hope this helps?

    Nick

    http://www.lightningtools.com
    Wednesday, March 03, 2010 7:42 AM
  • That is exactly what I ended up doing.  It is just a pain to build things that seem to have been skipped in the out of box services.  Then they need to be tested and migrated when SharePoint changes. Especially in this case where a client app will be integrating this service.

    Wednesday, March 03, 2010 2:30 PM
  • I complete agree with Nick. Since I had done this before for integrating Siebel-On-Demand with sharepoint. here's the link for same: http://patilmanishrao.wordpress.com/2009/11/15/integrate-siebel-crm-with-sharepoint/ 

    I regrate for not supplying the source code in the post, but the article still will be helpful.

    Regards


    Manish Patil http://patilmanishrao.wordpress.com Posting is provided AS IS with no warranties, and confers no rights.
    Friday, August 13, 2010 1:00 PM