0

I'm trying to create a lookup column on an Office 365 SharePoint dev site through an app using SPServices but I'm not having any luck.

function createLookupColumn(listGuid) {
    //alert($().SPServices.SPGetCurrentSite());
    var newField = '<Fields><Method ID="2"><Field type="Lookup" DisplayName="Marketing Plan" Required="FALSE" EnforceUniqueValues="FALSE" List="{'+listGuid+'}" ShowField="Title" UnlimitedLengthInDocumentLibrary="FALSE" Indexed="TRUE" RelationshipDeleteBehavior="Cascade" StaticName="Marketing_x0020_Plan" Name="Marketing_x0200_Plan" ColName="int1" RowOrdinal="0"/></Method></Fields>';
    //var newField = "<Fields><Method ID='1' Cmd='New'><Field Type='Text' DateOnly='TRUE' DisplayName='TESTText' FromBaseType='TRUE'/></Method></Fields>";
    $().SPServices({
        operation: "UpdateList",
        listName: "TestList",
        listProperties: "",
        updateFields: "",
        newFields: newField,
        deleteFields: "",
        listVersion: "",
        async: false,
        completefunc: function (xData, Status) {
            alert("Finished");
        }
    });

}

The SPServices library is loading b/c the commented out alert fires when uncommented. My listGuid arg isn't the problem either b/c I've tried uploading a basic xml file withouth overwriting the GUID (as noted in the second newField that's commented out) and that doesn't go through either. It's not failing, but it's just not creating any columns.

I've had similar problems as this in the O365 environment utilizing the get_XmlSchema and set_XmlSchema. In fact, I've never been able to set an XML on O365 and am really starting to wonder if it's even possible to overwrite XML in the cloud. What am I missing?

1

I had some trouble with this as well recently and found that if you make the DisplayName, StaticName and Name all the same, it works... below is an example I use today successful on O365... In this case, once the column was created, I sent a subsequent request to rename it (to "Release Date").

newField = '<Fields>' +
    '<Method ID="1" AddToView="">' +
        '<Field Type="DateTime" DisplayName="ReleaseDate" ' +
            'Required="TRUE" Format="DateOnly" ' + 
                'StaticName="ReleaseDate" Name="ReleaseDate" ' +
                'AllowDeletion="TRUE"/>' +
    '</Method>'  +
'</Fields>'
0

In your lookup <Field> tag, Type needs to have an initial uppercase letter. So, the corrected code would be:

var newField = '<Fields><Method ID="2"><Field Type="Lookup" DisplayName="Marketing Plan" Required="FALSE" EnforceUniqueValues="FALSE" List="{'+listGuid+'}" ShowField="Title" UnlimitedLengthInDocumentLibrary="FALSE" Indexed="TRUE" RelationshipDeleteBehavior="Cascade" StaticName="Marketing_x0020_Plan" Name="Marketing_x0200_Plan" ColName="int1" RowOrdinal="0"/></Method></Fields>';

If you still have issues, you can debug further by looking at xData.responseXML or xData.responseText (this one only works on Internet Explorer).

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.