Populating BCS Lookup field

Nov 7, 2013 at 11:32 AM
Hello,

I have 2 lists:
  1. List A is an external bcs list
  2. List B is a custom list with a lookup column to List A
I've been trying to create a new ListItem in list B that contains bcs lookup column but no luck,
I've come to conclusion that List A don't have __ows_ID__(aka ID) column however, what they have is ows_BdcIdentity column I'm not sure if I'm entirely correct though,
so as a good boy I tried to create an item in list B by concatenating
ListA_Item_BdcIdentity + ";#" + myValue
but it fired back at me with an error "Bad parameter passed to Web Server Extensions. Check the information you entered and try again"

And maybe what I'm trying to do is sort of impossible.

thanks,
Z
Nov 8, 2013 at 1:03 AM
I have not worked with BCS lists, but here is a suggestion: Use the Sharepoint out-of-the-box NewForm.aspx and create an item in list B ensuring you pick a value for the BCS list lookup column. Then, write a quick script that gets the row from the list using GetListItems and look at how the value you picked is returned. That will give you a clue as to the expected format.

Paul






--

_________
Paul T

Nov 8, 2013 at 10:39 AM
Sounds like a great idea, I'll give it a shot.

thanks,
Z
Nov 10, 2013 at 6:05 AM
I tried what you suggested, created an item by using the default OOTB form and then returned the item using GetListITems to see if it has any magic but nope, just an ordinary item with plain data which is weird, no lookup behavior whatsoever,
so yea

thanks,
Z
Nov 10, 2013 at 7:39 AM
Okay, I think I've figured it out.

SPServices has two methods of creating a new list item, one is all about valuepairs
batchCmd: "Update",
valuepairs: [["Title", "New Title Value"], ["Body", "Here is a the new text for the body column."]],
ID: 1234,
and the other one uses CAML Query
<Batch OnError='Continue' PreCalc='TRUE'>
  <Method ID='1' Cmd='New'>
    <Field Name='Title'>New Title Value</Field>
    <Field Name='Body'>Here is a the new text for the body column.</Field>
    <Field Name='ID'>1234</Field>
  </Method>
</Batch>
However one would assume that both methods would translate to the same SOAP xml request, and that didn't happen.

The first request using valuepairs method created this batch
<Batch OnError='Continue'>
    <Method ID='1' Cmd='New'>
        <Field Name='Title'>1</Field>
        <Field Name='LookupColumnToBcsList'>2</Field>
    </Method>
</Batch>
The second request using the CAML Query created this batch
<Batch OnError='Continue' PreCalc='TRUE'>
    <Method ID='1' Cmd='New'>
        <Field Name='Title'>1</Field>
        <Field Name='LookupColumnToBcsList'>2</Field>
    </Method>
</Batch>
The only difference was in the second request it had PreCalc attribute set to TRUE
Coordinator
Nov 10, 2013 at 2:40 PM
The valuePairs approach is intended as an easy shortcut for common updates.

I've never found any explanation for what PreCalc or some of the other potential attributes on the Batch element. If you can point me to anything useful (other than examples that include it), I'd appreciate it.

M.
Nov 10, 2013 at 2:41 PM
So it's fixed? Your able to update/create items and set the BCS column?

Regarding UpdateListItem:
SPServices only has one method - UpdateListItems. Mark has a value added feature (input params batchCmd and valuepairs) for that method that allows the developer to pass in an Array-of-Arrays with the columns to be updated for a specific row (when this approach is used, you can only create/update one item at a time.) This also liberates the developer from dealing with XML.

The alternative (which is realy the primary, IMO) is for the developer to define the XML themselves, which then gives you the full control of setting supported XML attributes and update/create multiple items in one shot. There are other XML attributes that are helpful (ex: MatchOnId). You should look at the API docs in the MS site. Mark has a link to it next to each method supported by SPServices.

Paul



--

_________
Paul T

Nov 10, 2013 at 2:42 PM
Sorry Mark. Looks like we responded at the same time. :)


--

_________
Paul T