Tuesday, 27 September 2016

Get All Lists Display and Internal Names and bind to Dropdown from Office 365 (SharePoint ) website using JSOM

Problem Statement- Need to Load all the Lists from current web in a drop down

Solution: Find below the snippet to get all List and bind to drop down.

Drop down option will have Text as Display name and Value as Internal Name of the list. I am aware for some people this is cakewalk but for first timer might be helpful as below snippet take care of A sync call as well.

code :
// Load dropdown function 
loadDropDown:function(){

//Call getAllLists method and then pass the ListCollection to Bind to dropdown
   getAllLists().then(function (listCollection) {
            bindListDropDown(listCollection);
        }
}

  /*********************************************************************************************************
* Name: getAllLists
* Description: Get all List from current web
* Parameters: None
*********************************************************************************************************/
    getAllLists: function () {
        try {
            var context = new SP.ClientContext.get_current(),
                 web = context.get_web(),
                 dfd = new $.Deferred(),
                 relatedInformationList,
                 listCollection;
            listCollection = web.get_lists();
            context.load(listCollection, "Include(Title, DefaultViewUrl,BaseTemplate)");
            context.executeQueryAsync(
                                      function () {
                                          return (dfd.resolve(listCollection));
                                      },
                                      function () {

                                          return dfd.reject();
                                      });
            return dfd.promise();
        }
        catch (error) {
          //error log
        }
    },
    /*********************************************************************************************************
* Name: bindListDropDown
* Description: Bind al the Lists to the DropDown
* Parameters: listCollection
*********************************************************************************************************/
    bindListDropDown: function (listCollection) {
        var listCollectionEnumerator = listCollection.getEnumerator(),
            listName = "",
            listInternalName = "",
            option = $("
      
        $("#ddlListName").append(option);
        while (listCollectionEnumerator.moveNext()) {
            {
                var baseTemplate = listCollectionEnumerator.get_current().get_baseTemplate();
                var defaultViewUrl = listCollectionEnumerator.get_current().get_defaultViewUrl();
                defaultViewUrl = defaultViewUrl.replace(_spPageContextInfo.webServerRelativeUrl, "");
                defaultViewUrl = defaultViewUrl.split("/");

                if (baseTemplate == 100) // get only custom list to be displayed if you want Document //Library only use 101
{
                    listInternalName = defaultViewUrl[2];
                    $("#ddlListName").append($("").val(listCollectionEnumerator.get_current().get_title()).html(listCollectionEnumerator.get_current().get_title()));
                }
            }
        }

    },

Let me know if you have any query.





Tuesday, 19 April 2016

Create cascaded Cross site Look up column in SharePoint office 365

Problem Statement

Cascade Cross site lookup column in office 365 SharePoint Hosted app.

let me explain the requirement.

There are three Lists namely Country City and District present in Root site of a web application (https://www.abc.com/)

Now they want to create a Column name UserCountry UserCity and UserCity in a List called Consumer with lookup at this site( https://www.abc.com/sites/Consumer ). These three Column data should be coming respectively from Country,City and District column of root site.  There should be a feature of filtering the Column value in drop down like if Country USA is selected only cities related with USA should be shown in City column Dropdown in New or Edit form of the List Consumer.

Some thing like below screenshot we need to get the output. This should be achieved with SharePoint hosted app only.

Cascade Cross site Lookup



I request please provide your opinion to this Problem in comment box.

 will try to provide the solution in near future