I'm trying to create a couple of lists automatically using REST.
List A:
TextField: ID
TextField: Name
List B:
LookupField: ID (Get from list A)
LookupField: ID:Name (Additional read-only column)
Using the UI I can simply go to the settings of the lookup field ID in list B and tick the checkbox "Name" from the list "Add a column to show each of these additional fields:" However, I struggle to do the same using REST. Does anyone know if this is possible?
I have tried to create additional lookup fields using SP.Field, but I cannot find any way to set the PrimaryFieldID.
The following produces the error: 400 Bad Request. Even if I change the type from SP.Field to SP.FieldLookup.
$.ajax({
url: "http://<site url>/_api/web/lists(guid'da58632f-faf0-4a78-8219-99c307747741')
/fields('1d22ea11-1e32-424e-89ab-9fedbadb6ce1')",
type: "POST",
data: "{ '__metadata': { 'type': 'SP.FieldLookup' }, 'PrimaryField': <Guid of list B field ID> }",
headers: {
"X-RequestDigest": <form digest value>,
"content-type": "application/json;odata=verbose",
"content-length": <length of body data>,
"X-HTTP-Method": "MERGE"
},
success: successHandler,
error: errorHandler
});
Thanks!