In The Mix

As a SharePoint architect I have the business behind me and the Developers and IT Pro on my shoulders.

Remote SharePoint Development using CloudShare December 16, 2013

Filed under: SharePoint 2013 — fmuntean @ 2:50 pm

There are many ways to develop SharePoint 2013 solutions or apps.

Some of these options are:

  • Have SharePoint locally on the laptop or on a VM.
  • Use Office 365 SharePoint Online and have Visual Studio installed locally.
  • Use a VM online like Azure and CloudShare then remote into those to do development.

and now there is one more:

  • Use CloudShare to install SharePoint 2013 and have Visual Studio installed locally.

Personally I like the option to develop using SharePoint Online however I would like to have a little bit more control over the SharePoint Farm that I develop against. So I start looking into alternatives and found one:

Using CloudShare and have both options of developing on the VM itself and remotely like with the SharePoint Online. For this to happen we need to enable the SharePoint to be available on the internet and enable SharePoint Apps infrastructure to be available on the internet too.

Danny Jessee posted on CloudShare  Blog (http://blog.cloudshare.com/2012/11/09/setting-up-the-cloudshare-sharepoint-2013-rtm-farm-to-support-apps/) showed how to enable Apps inside SharePoint using a local DNS server.

We will turn that around and use a public DNS server which would help us getting Apps working inside SharePoint from the Internet.

To make things simpler and be able to follow the entire process I put together all the steps necessary to create a single server Farm with Apps enabled from the internet: (if you only look on how to enable the remote app development check step 3 bellow)

  1. Install single SP Server VM
    1. Windows Server 2012
    2. SharePoint Foundation 2013 (single server Farm)
      1. Prerequisites
      2. Install binaries
      3. SharePoint Products Configuration Wizard
  1. Extend the SP WebApp to use the external URL
    1. The initial installation creates a Web App that uses the computer name. CloudShare provides a static external url to access the VM so we will use this URL to access SharePoint from Internet by extending the Web App to respond to this URL
  2. Configure the SP App domain to point the external address
    1. What we need is a wildcard CNAME DNS entry to a custom domain that will be used by SharePoint to generate apps urls.
    2. For this we will use a www.cloudns.net free subdomain which allows
    3. Create new zone and Configure a Wildcard CNAME DNS entry for the  external address of the VM

I have created a zone under cloudns.us named spapps and then added a CNAME entry: (use your own zone name)

*.spapps.cloudns.us

 CNAME  External url for the SharePoint VM from step 2 above
  1. Configure SP to point to the newly created app domain

Central Admin -> Apps -> Configure App URLs
(need to have “App Management Service” and “SettingsServiceApp” installed and running: Follow http://technet.microsoft.com/en-us/library/fp161236.aspx on how to get those two services up and running.)

ConfigureAppUrls

Associate the App Service Proxy with the Web App

Central Admin -> Application Management -> Service Applications -> Configure Service Application Associations

  1. Create App Catalog (optional)
  2. Add an app form the SharePoint store ( World Clock and Weather from Bamboo Solutions should do it)
  3. Create a Developer site collection
    /sites/dev using Developer site Template
  4. Start Visual Studio and Happy codding SP Apps remotely.

With this approach I am able to develop remotely with no need to remote desktop and I also have full access to the SharePoint Farm to configure it as I see fit.

 

Adding Primary and Dependent Lookup Fields using JSOM October 7, 2013

Filed under: JavaScript,SharePoint,SharePoint 2013 — fmuntean @ 9:10 am

There is a lot of information out there on how to add Lookup fields using JSOM or JavaScript Client Object Model but there is no info on how to add dependent lookup fields.

The MSDN documentation is sketchy at best and does not even document the necessary parameters.

After some fiddling  around with a useless server response and many combination of calls and thanks to Fiddler help I got the secondary lookup fields working.

So to keep this short the code samples are as follow:

1. Adding primary Lookup field:

/// Parameters:
/// clientContext:     the JSOM clientContext
/// onList:            the current list where the lookup field has to be created
/// toList:            the list where this lookup field will look for the data
/// fieldXml:          the xml definitionn for the lookup field
/// toLookupFieldName: the field name in the toList that is used to copy the value over.
///
var AddPrimaryLookupField = function(clientContext, onList, toList,fieldXml, toLookupFieldName)
{
  // Add Lookup Field
  var field = onList.get_fields().addFieldAsXml(fieldXml,true,SP.AddFieldOptions.defaultValue);

  //cast the field to a lookup field
  var fieldLookup = clientContext.castTo(field, SP.FieldLookup);

  //Setting up the Lookup list ID and the Field to lookup inside that list
  fieldLookup.set_lookupList(toList.get_id());
  fieldLookup.set_lookupField(toLookupFieldName || "Title");

  fieldLookup.update();

  clientContext.load(field);

  clientContext.executeQueryAsync(
    Function.createDelegate(this, function () {
    //success code here
    }),
    Function.createDelegate(this, function (sender, args) {
    //failure code here
  }));
}

2. Adding dependent or secondary lookup fields:

/// Parameters:
/// clientContext:     the JSOM clientContext
/// onList:            the current list where the lookup field has to be created
/// toList:            the list where this lookup field will look for the data
/// toLookupFieldName: the field name in the toList that is used to copy the value over.
/// lookupFieldName:   the name of the dependent lookup field
///
var AddDependentLookupField = function(clientContext, onList, lookupFieldName, toList, toLookupFieldName)
{
  //get the field to be linked to
  var toField = toList.get_fields().getByInternalNameOrTitle(toLookupFieldName);

  // Add dependent Lookup Field
  var field = onList.get_fields().addDependentLookup(lookupFieldName, primaryField, toField);
  //cast the field to a lookup field
  var fieldLookup = clientContext.context.castTo(field, SP.FieldLookup);
  // Even if we specify the field in the addDependentLookup we still have to set it here again
  fieldLookup.set_lookupField(toLookupFieldName || "Title");

  field.update();
  clientContext.context.load(field);

  clientContext.context.executeQueryAsync(
    Function.createDelegate(this, function () {
      //success code here
    }),
    Function.createDelegate(this, function (sender, args) {
     //failure code here
  }));
}