5

As the Title say, all what I need is update a column with multiple lookup values. This is how I set the metadata

var someNumbers = [4, 5];
var itemMetadata = {
    '__metadata': {
          'type': archivo.d.ListItemEntityTypeFullName
    },
    'GerenciaId': $('#gerencia').val(),
    'Planta_AreaId': $('#planta').val(),
    'Tipo_ArchivoId': $('tipoarchivo').val(),
    'Familia_ControlId': someNumbers //<-- multi lookup
};

I guess it shuold by some kind of array, but i cant figure it out.

Dont worry about the rest of the code, is already working.

Thanks :)

2 Answers 2

6

You are right that it should be an array - array of ID's of the referenced items.

Try the following:

var someNumbers = [4, 5];
var itemMetadata = {
    '__metadata': {
          'type': archivo.d.ListItemEntityTypeFullName
    },
    'GerenciaId': $('#gerencia').val(),
    'Planta_AreaId': $('#planta').val(),
    'Tipo_ArchivoId': $('tipoarchivo').val(),
    'Familia_ControlId': {
       'results' : someNumbers
     }
};

So basically if you have multiple values in lookup field (it also applies to User fields, as technically speaking they are lookups), instead of just passing the array of numbers, you have to place the array with numbers in new object under the results key.

0
2

In my experience you need to emulate what you get when you do a read (which you can see using a tool like Fiddler). In your case the code would be:

var someNumbers = [4, 5];
var itemMetadata = {
    '__metadata': {
        'type': archivo.d.ListItemEntityTypeFullName
    },
    'GerenciaId': $('#gerencia').val(),
    'Planta_AreaId': $('#planta').val(),
    'Tipo_ArchivoId': $('tipoarchivo').val(),
    'Familia_ControlId': {
        '__metadata': { type: 'Collection(Edm.Int32)' },
        'results': someNumbers 
     }
};

I cover this in Update MultiSelect Choice and Lookup Field Values from JavaScript CSOM and REST API on YouTube

1
  • 1
    works wonderfull :) Thanks a lot
    – Marco
    Jun 30, 2015 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.