4

I have two lists. The first one has customers and the second one has Orders. Now i want to add some (test) data in the elements.xml of the listinstances. For customers this works without a problem

    <Row>
      <Field Name="Id">1</Field>
      <Field Name="FirstName">Beni</Field>
      <Field Name="LastName">Egli</Field>
    </Row>

Now I want to do the same for the orders. An order is linked to a customer via a lookupfield. I also want to set the date to (for example) today.

    <Row>
      <Field Name="Id">1</Field>
      <Field Name="CustomerLookup">2</Field>
      <Field Name="Date">[today]</Field>
    </Row>

The Date=[Today] can't even deploy and when I remove the date line no entries are added (date is not required)

3
  • how did u create Date Field? I think u should set default value when u r creating ur field
    – user7676
    Apr 3 '12 at 8:19
  • I agree, set the Date field to have a default value of Today/Now.
    – Ian
    Apr 3 '12 at 9:25
  • You could also inject data on feature activated, then you have full control of what and how you add data
    – eirikb
    Sep 12 '12 at 6:14
1

This will not work because Sharepoint will eventually put every list item in the same table in the database. The order item will not be added since an item with ID=1 already exists. (the customer item).

It is not recommended to add list items this way, and as suggested above you could use a feature event receiver to add items instead.

If you would like to use the xml make sure that the ids do not match. This can be tricky when you get a lot of lists and items in them.

1

I don't know about the lookup field but for date field you can write this way:

<Row>
  <Field Name="Id">1</Field>
  <Field Name="Date">2011-12-30T21:00:00Z</Field>
</Row>

Refer this discussion for more details.

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.