Saturday, June 11, 2016

get lookup additional fields as part of rest call

{WebUrl}/_api/web/lists/GetByTitle('SPR_RequestItems')/Items?$select=SPR_RequestItem_SAP_MaterialCode/SPR_SAP_MaterialCode,SPR_RequestItem_SAP_MaterialCode/SPR_SAP_MaterialDescription&$filter=SPR_RequestNumber%20eq%20144&$expand=SPR_RequestItem_SAP_MaterialCode&$top=5000

Tuesday, June 7, 2016

Add multiple items in sharepoint list using JSOM

var itemArray = [];
   for (var i = 1; i <= totalSPRIRowsCount; i++)
   {
       
           var listspRequests = context.get_web().get_lists().getByTitle(listspRequestsTitle);
           var newItemInfo = new SP.ListItemCreationInformation();
           newItemInfo.set_folderUrl(_spPageContextInfo.webAbsoluteUrl + "/Lists/SPR_RequestItems/" + curdate.getFullYear() + "/" + monthNames[curdate.getMonth()]);
           var spRequestItem = listspRequests.addItem(newItemInfo);
           UpdateSPRequestItem(spRequestItem,i);
           itemArray.push(spRequestItem);
           context.load(itemArray[itemArray.length-1]);
   }
   context.executeQueryAsync(
                       function(sender,args)
                       {
                           //waitDialogSubmit.close(SP.UI.DialogResult.OK);
                           SendMailOnSubmit();
                       },
                       function (sender, arg)
                       {
                           alert("error in update request : " + arg.get_message());
                           //waitdialogsubmit.close(sp.ui.dialogresult.ok);
                           redirectoncompletion();
                       });

Defered object usage in sharepoint

function getCachedSearches() {
    var dfd = $.Deferred(function () {
        var list = context
                .get_web()
                .get_lists()
                .getByTitle('MyList');

        cached_searches = list.getItems('');

        context.load(cached_searches);

        context.executeQueryAsync(
           function () {
               dfd.resolve();
           },
           function (sender, args) {
               dfd.reject(args.get_message());
           }
        );
    });
    return dfd.promise();
}

function addCachedSearch(phrase) {
    var dfd = $.Deferred(function () {
        var list = context
                .get_web()
                .get_lists()
                .getByTitle('CachedSearches');

        var create_item = new SP.ListItemCreationInformation();
        var list_item = list.addItem(create_item);

        list_item.set_item('Title', phrase);

        list_item.update();

        context.load(list_item);

        context.executeQueryAsync(
           function () {
               dfd.resolve();
           },
           function (sender, args) {
               dfd.reject(args.get_message());
           }
        );
    });
    return dfd.promise();
}

function doSearch() {
    addCachedSearch($('#phrase').val())
        .then(getCachedSearches);
}

Saturday, November 21, 2015

Client-side People Picker control for Sharepoint

$(document).ready(function () {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
})

function sharePointReady() {
    context = new SP.ClientContext.get_current();
    web = context.get_web();
    getUser().done(function (user) {
        var schema = {};
        schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
        schema['SearchPrincipalSource'] = 15;
        schema['ResolvePrincipalSource'] = 15;
        schema['AllowMultipleValues'] = false;
        schema['MaximumEntitySuggestions'] = 50;
        schema['Width'] = '280px';

        var users = new Array(1);
        var defaultUser = new Object();
        defaultUser.AutoFillDisplayText = user.get_title();
        defaultUser.AutoFillKey = user.get_loginName();
        defaultUser.Description = user.get_email();
        defaultUser.DisplayText = user.get_title();
        defaultUser.EntityType = "User";
        defaultUser.IsResolved = true;
        defaultUser.Key = user.get_loginName();
        defaultUser.Resolved = true;
        users[0] = defaultUser;
        SPClientPeoplePicker_InitStandaloneControlWrapper('peoplePickerDiv', users, schema);
    });
}

function getUser() {
    var dfd = $.Deferred(function () {
        user = web.get_currentUser();
        context.load(user);
        context.executeQueryAsync(
            function () {
                dfd.resolve(user);
            }),
            function () {
                dfd.reject(args.get_message());
            };
    });
    return dfd.promise();
}

Thursday, November 12, 2015

JSLink Urls

JSLink URLs and Tokens
When you are constructing your JSLink URL there are a number of tokens you can take advantage of:
  • ~site – reference to the current SharePoint site (or “Web”)
  • ~sitecollection – reference to the current SharePoint site collection (or “Site”)
  • ~layouts – version specific reference to the web application Layouts folder (so it will automatically swap out /_layouts/14 or /_layouts/15 for you)
  • ~sitecollectionlayouts – reference to the layouts folder in the current site collection (e.g. /sites/team/_layouts/15)
  • ~sitelayouts – reference to the layouts folder in the current site (e.g. /sites/teams/subsite/_layouts/15)

Friday, November 6, 2015

Export to Excel using javascript

http://www.c-sharpcorner.com/UploadFile/65794e/export-from-html-table-using-jquery/

Thursday, November 5, 2015

How to get spfielduser value in REST call ?


use below kind of query to get the SPFieldUserValue in REST based call

url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/Items?$select=Title,EmployeePhone,LeaveCategory,EmployeeLocation,EmployeeName/Title&$expand=EmployeeName&$filter="+ restQuery,