0

I have a sharepoint-hosted app containing a custom list. On the host site collection where I am deploying this app, there are several custom site columns.

In my app, I want to access these site columns and include as columns in my custom list.

Is this possible?

2

Yes, it is possible. I created a site column called Test in the Host Web and then I used this code to add it to a list in the App Web.

$(document).ready(function () {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var fields = web.get_availableFields();
    var testField = fields.getByTitle("Test");

    var lci = new SP.ListCreationInformation();
    lci.set_title("Test");
    lci.set_templateType(SP.ListTemplateType.genericList);
    var list = web.get_lists().add(lci);

    list.get_fields().add(testField);

    context.executeQueryAsync(success, fail);

    function success() {
        var message = jQuery("#message");
        message.text("List added");
    }

    function fail(sender, args) {
        alert('Error:' + args.get_message());
    }
});

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.