SharePoint Hosted App - Create a cascading drop-down list in hosted web lists

I created a SharePoint hosting application (Javascript Object Model) that creates lists on the host network.

I need to put some javascript in new ones and edit the forms to create a cascading effect of falling into 2 search fields.

This is how I create lists and fields for it:

    // Create a new list on host web
    var createList = function (listTitle, onSuccess, onFieldsReady) {
    var listCreationInfo = new SP.ListCreationInformation();
    listCreationInfo.set_title(listTitle);
    listCreationInfo.set_templateType(SP.ListTemplateType.genericList);

    var lists = hostWeb.get_lists();
    var newList = lists.add(listCreationInfo);

    currentContext.load(newList);
    currentContext.executeQueryAsync(onSuccess(newList, onFieldsReady), onListCreationFail);
}

    // Create a new field on a list
    var createField = function (list, fieldType, fieldName, fieldDisplayName, fieldRequired, onSuccess) {
    var fields = list.get_fields();
    var fieldXml = "<Field Type='" + fieldType + "' Required='" + fieldRequired + "' DisplayName='" + fieldDisplayName + "' Name='" + fieldName + "'></Field>";
    var createdField = fields.addFieldAsXml(fieldXml, true, SP.AddFieldOptions.addFieldInternalNameHint | SP.AddFieldOptions.addFieldToDefaultView);

    currentContext.load(createdField);
    currentContext.executeQueryAsync(onSuccess, onProvisionFieldFail);
}

Could you give me some advice?

Hi,

Marian

+4
source share
2 answers

You should consider using the ideas of NewForm and Editform.aspx. Just write your own form and use JSOM or WebApi to add / edit list items.

:

jQuery.ajax({
    url: "http://<site url>/_api/web/lists/GetByTitle('Test')",
    type: "POST",
    data: JSON.stringify({ '__metadata': { 'type': 'SP.List' }, 'Title': 'New title' }),
    headers: { 
        "X-HTTP-Method":"MERGE",
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
        "content-length": <length of post body>,
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
        "IF-MATCH": "*"
    },
    success: doSuccess,
    error: doError
 });

: http://msdn.microsoft.com/en-us/library/office/jj164022(v=office.15).aspx

0

.

var clientContext = new SP.ClientContext.get_current();
var list = clientContext.get_web().get_lists().getByTitle('ListName');

if(list) {
    var fldCollection = list.get_fields();

    var fieldLookup1 = clientContext.castTo(
        fldCollection.addFieldAsXml('<Field Name="FieldName1" Type="Lookup" DisplayName="My Lookup Field 1" List="Lists/MyLookupList" ShowField="Title" />', true, SP.AddFieldOptions.addToDefaultContentType),
        SP.FieldLookup
    );

    fieldLookup1.set_title("MyLookupField1");
    fieldLookup1.set_description("Lookup field 1 description");
    fieldLookup1.update();
    list.update();

    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded),
        Function.createDelegate(this, this.onQueryFailed)
    );
}

, , ;)

!

0

Source: https://habr.com/ru/post/1543024/


All Articles