Tuesday, September 30, 2014

Thursday, September 25, 2014

SharePoint App: replace SP.RequestExecutor 'executor.executeAsync' with Jquery '$.ajax'

OBJECTIVE


To replace the SharePoint executor  with a Jquery ajax call.

NOTE

Several months ago, after an O365 update, the SP.RequestExecutor stopped working. 
As a consequence all the app installed on O365 that used SP.RequestExecutor, started having issues.
If you had an app on the Store used by many clients, you probably have received a lot of support calls.
We have replaced it with a Jquery ajax call, and the problem was solved.

This is not a MS best practice, but it's good to know your alternative.


EXAMPLE 

This example was built using SharePoint hosted app and js. 
 hostweburl: is the value of "SPHostUrl" token.
 appweburl: is the value of "SPAppWebUrl" token


The following SP.RequestExecutor:

 LibraryInfo.GetListViewFieldDetails_ClientOM();
 var executor = new SP.RequestExecutor(appweburl);
 var executor = new SP.RequestExecutor("/");
 executor.executeAsync({
                url: "http://...",
                method: "GET",
                headers: { "Accept": "application/json; odata=verbose" },
                success: LibraryInfo.successHandlerListId,
                error: LibraryInfo.errorHandlerListId
            });


can be replace with:

 $.ajax({
                url: "http://...",
                headers: { Accept: "application/json;odata=verbose" },
                success: LibraryInfo.successHandlerListId,
                error: LibraryInfo.errorHandlerListId
            });

Wednesday, September 24, 2014

SharePoint App: Use REST to get fields from a list filtered by field type with ECMAScript

OBJECTIVE


To programmatically obtain all the fields from a list with field type = "TaxonomyFieldType" (or the required type).

SOLUTION


1 - Get List: getbytitle
2 - Get all fields: /fields
3 - Filter this result: $filter=startswith(TypeAsString,'TaxonomyFieldType')
4 - Query: /_api/SP.AppContextSite(@target)/web/lists/getbytitle('MyCustomListTitle')/fields/?$filter=startswith(TypeAsString,'TaxonomyFieldType')&@target='" + hostweburl + "'"

EXAMPLE 


This example was built using SharePoint hosted app and js. 
The REST query can be used in different context.
 hostweburl: is the value of "SPHostUrl" token.
 appweburl: is the value of "SPAppWebUrl" token

var executor = new SP.RequestExecutor(appweburl);
var executor = new SP.RequestExecutor("/");
executor.executeAsync({
    url: TagCloudMain.appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('MyCustomListTitle')/fields/?$filter=startswith(TypeAsString,'TaxonomyFieldType')&@target='" + hostweburl + "'",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: LibraryInfo.successHandlerListId,
    error: LibraryInfo.errorHandlerListId
});

Monday, September 22, 2014

SharePoint On-Premises vs. Online


An interesting session from SPTechCon Boston 2014, about SP On-Premises, Online and Hybrid solutions.



Wednesday, September 17, 2014

SharePoint App Model Samples

When the SharePoint community get together, the result is the Office AMS Program, also know as Office 365 Developer Patterns & Practices. 







If you are looking for code example, this Codeplex project is what you need. 
Branding, Deploy, Permission, Timer Job, Event Receiver and much more. 

Download source code and documentation here.

From Full Trust to App Model

If you are planning to move your old portal to the app model, you are probably asking yourself if it’s possible to convert Full Trust solutions to Apps.
The answer is:  “There isn't any 1 to 1 conversion, but you can be redisigned the solution in Apps”.

At the SharePoint Conference 2014 Vesa Juvonen and Steve Walker presented the session: “Real-world examples of FTC to CAM transformations Real-world examples of FTC to CAM transformations Real-world examples of FTC to CAM transformationsReal-world examples of FTC to CAM transformations” where they talked in details about this topic", Here the original link.

Session Video:

Thursday, October 27, 2011

PeopleEditor To SPFieldUserValueCollection

OBJECTIVE
To programmatically copy people selected from an asp.net People Editor to a SPFieldUserValueCollection field.

SPECIFICATION
The People Editor can contain multiple people, and allow Users and Groups selection.

SOLUTION
// myPeopleEditor is a PeopleEditor object in my asp.net form.

..
Item[“MyUserField”] = GetPeople(myPeopleEditor, Web);
..


private SPFieldUserValueCollection GetPeople(PeopleEditor people, SPWeb web)
{
  SPFieldUserValueCollection values = new SPFieldUserValueCollection();
  if (people.ResolvedEntities.Count > 0)
  {
    for (int counter = 0; counter < people.ResolvedEntities.Count; counter++)
    {
        PickerEntity user = (PickerEntity)people.ResolvedEntities[counter];
        switch ((string)user.EntityData["PrincipalType"])
        {
          case "User":
            SPUser webUser = web.EnsureUser(user.Key);
            SPFieldUserValue userValue = new SPFieldUserValue(web, webUser.ID, webUser.Name);
            values.Add(userValue);
          break;
 
          case "SharePointGroup":
            SPGroup siteGroup = web.SiteGroups[user.EntityData["AccountName"].ToString()];
            SPFieldUserValue groupValue = new SPFieldUserValue(web, siteGroup.ID, siteGroup.Name);
            values.Add(groupValue);                       
          break;
        }
      }
    }
    return values;
  }