0

in my project, there is a picture library with a look field. I delete and create this lookup field like that :

function MajBibliPhotoGare()
{
    var clientContext =SP.ClientContext.get_current();
    var field = clientContext.get_web().get_lists().getByTitle('BibliPhotoGare').get_fields().getByInternalNameOrTitle('IDListeGare');
    clientContext.load(field);
    clientContext.executeQueryAsync(
    Function.createDelegate(this,function() 
        {
            // effacer IDListeGare
            field.deleteObject();
            clientContext.get_web().update();
            clientContext.executeQueryAsync(
            Function.createDelegate(this,function()
                {   
                    // Create lookup Field IDListeGare
                    var oList = clientContext.get_web().get_lists().getByTitle('BibliPhotoGare');
                    var fieldColl = oList.get_fields();   
                    var fieldSchema='';
                    //Add Look up field to the Field Collection  
                    var lookupField = fieldColl.addFieldAsXml(fieldSchema, true, SP.AddFieldOptions.addToDefaultContentType) ; 
                    fieldColl.addFieldAsXml(fieldSchema, true, SP.AddFieldOptions.addToDefaultContentType) ;   
                    lookupField.update(); 
                    clientContext.executeQueryAsync(
                        // Field OK
                        Function.createDelegate(this,function()
                            {
                                // Field OK
                                alert('ok');
                            }), 
                        Function.createDelegate(this, function()
                            {
                                // Field not OK
                                alert(' Not ok');
                            })
                        );
                }),
                Function.createDelegate(this, function()
                    {
                        // error deleting lookup field
                        alert('error deleting lookup field IDListeGare')
                    })
            );
        }),
        Function.createDelegate(this,function()
            {
                // error loading lookup field
                alert('error loading lookup field IDListeGare')
            })
    );      
}

The code is running well, and when i look at the picture library, there is two lookup field named IDListeGare BibliPhotoGare picture Library result

Thank you fo your help.

1
  • Is there any update? Don't forget to accept the helpful answer as the best answer if it resolves your problem. Oct 12, 2018 at 6:24

1 Answer 1

0

You are creating duplicate lookup fields in your code:

var lookupField = fieldColl.addFieldAsXml(fieldSchema, true, SP.AddFieldOptions.addToDefaultContentType) ; 
fieldColl.addFieldAsXml(fieldSchema, true, SP.AddFieldOptions.addToDefaultContentType) ;   

Remove the second row, only add one field:

var lookupField = fieldColl.addFieldAsXml(fieldSchema, true, SP.AddFieldOptions.addToDefaultContentType) ; 
0

Your Answer

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

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