Yet another fix for "App with the same version and product ID" on-premises

"The provided App differs from another App with the same version and product ID"

Ever since the beginning of 2013, we have this this problem when you deploy and redeploy App (now SharePoint Add-in) to either SharePoint 2013 on-premises or Office 365's SharePoint Online.

If you Bingle about - you will find various fixes, in order of severity:

1 - you can try to retry Installing the App, or removing it from Site Content http://www.mavention.nl/blog/provided-App-differs-another-App-same-version-product-ID

2 - try removing it from Site and Site Collection recycle bins.  Also remember the second level recycle bin.  This one is usually good enough for Office 365.

3 - Jeremy Thake says don't use the same farm account http://www.jeremythake.com/2013/10/sharepoint-2013-apps-the-provided-app-differs-from-another-app-with-the-same-version-and-product-id/

4 - You can also just increment the version number.  This is difficult when you work in a team and you don't want to bump _everyone_'s number

5 - Delete the offending Site Collection and create a new one

I found a new, TOTALLY UNSUPPORTED WAY.

Sometimes, you really just want to delete the old one.  But the Object Model doesn't have objects that go that deep.  Hence there are no way to do this via command-line either.

You need AppInstance to perform an uninstall.  If you can't get an AppInstance, but the AppPackage is still in your Site Collection, you are pretty much stuck.

Let's go check out the content database.  Disclaimer: Do this if you are curious.  Also, don't do this on your production.

SELECT [PackageFingerprint]
      ,[ProductId]
      ,[Package]
      ,[Title]
      ,[IsDownloadInvalidated]
      ,[SiteId]
  FROM [WSS_CONTENT_DB].[dbo].[AppPackages]

You want to know which Site Collection it is.  So figure out which AppPackage is the one SharePoint can't delete - by cross-checking the SiteId

PackageFingerprint is an important field that we'll need in a minute.  It acts like a unique identifier.
IsDownloadInvalidated is probably 0 (meaning it is valid).  You just can't delete it.

SharePoint has a few nice store procedures.

exec [WSS_CONTENT_DB].[dbo].proc_App_InvalidatePackage
    @PackageFingerprint, @SiteId

-- example
exec [WSS_CONTENT_DB].[dbo].proc_App_InvalidatePackage
    0x9DB9C067E1B970AD1258E28AE26EC3AE17CF772BC093D0CCF8E1832FF3B171261A09812778830621AA63FD4C9D1EA922DC5432E1CACDEA00B1CDA82F9A28CAE2, 
    '282292D5-3686-460D-9AB4-9354272FB2A1'

This stored procedure will flag the AppPackage as Invalid.  If you do SELECT * FROM AppPackages again, you'll see it is now IsDownloadInvalidated = 1

So SharePoint now thinks there was something wrong with the download of this package :-)Let's invoke SharePoint's auto-immune system and nuke the AppPackage

exec [WSS_CONTENT_DB].[dbo].proc_App_DeleteInvalidatedDownloadApp
    @PackageFingerprint, @SiteId

-- same arguments.  

This one will nuke the AppPackage clean.

You can now go back to PowerShell and redeploy your App.

PS> $App = Import-SPAppPackage -Path <Path> -Site <Url> -Source <Source>
PS> Install-SPApp -Web <Url> -Identity $App 

This works really well.  But you REALLY shouldn't touch the Content DB

 

Convert SharePoint JSOM's ExecuteQueryAsync to Promise in the Prototype

Today's blog is about adding an additional method to SharePoint JavaScript Object Model (JSOM)'s ClientContext object, so we can use it directly like a promise.

I call it "executeQuery" (instead of executeQueryAsync)

Wrapper with jQuery's $.Deferred

SP.ClientContext.prototype.executeQuery = function() {
   var deferred = $.Deferred();
   this.executeQueryAsync(
       function(){ deferred.resolve(arguments); },
       function(){ deferred.reject(arguments); }
   );
   return deferred.promise();
};

Wrapper with AngularJS's $q

SP.ClientContext.prototype.executeQuery = function() {
   var deferred = $q.defer();
   this.executeQueryAsync(
       function(){ deferred.resolve(arguments); },
       function(){ deferred.reject(arguments); }
   );
   return deferred.promise;
};

How do you use this?

var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var promise = ctx.executeQuery(); // look!  :-)

promise.done(function(){
  console.log(web.get_title());
});
promise.then(function(sArgs){
  //sArgs[0] == success callback sender
  //sArgs[1] == success callback args
}, function(fArgs){
  //fArgs[0] == fail callback sender
  //fArgs[1] == fail callback args.
  //in JSOM the callback args aren't used much - 
  //the only useful one is probably the get_message() 
  //on the fail callback
  var failmessage = fArgs[1].get_message();
});

This may seem to be just small syntactic sugar, but now you have JSOM returning a promise that you can chain, loop, combine and juggle to your heart's content!

Remember, jQuery.ajax, SPServices, AngularJS, and now JSOM all returns promise objects now.

2015 Xbox One Black Friday Edition

USA

Best Console Deals

http://deals.dell.com/compare/X500GOWFALLTD

$299
Gears of War: Ultimate Edition Bundle (that's 4 games) 
Fallout 4 (and Fallout 3 code next week) (that's 2 more games)
+extra controller
think this one is completely sold out.

http://www.bestbuy.com/site/microsoft-xbox-one-rise-of-the-tomb-raider-bundle-black/4512300.p?id=1219756880977&skuId=4512300

$349
Both Tomb Raiders.  (2 games)
Extra controller. 
1 TB HD (standard is 500 GB).

Xbox Live Gold

Buy 1 month for $1 from within the console.  Then buy 12 month for ~$30 via CDKeys.  Don't buy Xbox Live Gold monthly at $10/month. 

Gold is necessary for online play and you get up to 4 free games per month.  You need to go buy Xbox Live Gold.

EA Access

If you like EA's many games: Dragon Age, Battlefield, Titanfall, PvZ, Need for Speed, and their endless line of sports games.  Then pop down $30/year for EA Access all-you-can-eat pass.

Accessories

http://www.microsoftstore.com/store/msusa/en_US/list/categoryID.70508400?icid=XboxOneR_ModD_BFCM_WirelessControllers_112615

Multiple special controllers on sale.

Hard Drive

Standard console comes with 500GB.  This is not enough.  But Xbox One can use up to two more external harddrives at once.  I prefer 2TB Western Digital or Seagate portable harddrives - they can draw power from the XB1 directly and you don't need an extra plug.  Because of XB1's Hyper-V setup, external HD actually runs faster than internal HD.  These are regularly around US$65 and dropping.

Games

I buy Digital. 
http://majornelson.com/2015/11/26/black-friday-xbox-digital-game-deals/

There's extra discounts if you are an Xbox Live Gold member, which is $1 for this month.

Kinect, TV Tuner

If you are on the edge about whether you need these, pass.  They have their place and I love them, but Black Friday is about awesome deals and you can skip these.

 

Enabling LastPass bookmarklet with Microsoft Edge

One of the problems of Microsoft's Edge browser not supporting Extensions right now is that password management with tools like LastPass can be quite difficult.

Here is a workaround with LastPass via Bookmarklets

You need the help of another browser - either IE or Chrome. 
Because Edge doesn't currently have a way to create/modify bookmarklets

1. In IE/Chrome.  Login to your LastPass https://lastpass.com/index.php?ac=1

2. Browser down Tools > Bookmarklet

 

 3. In IE/Chrome.  Drag LastPass Fill! Into the Favourites Bar (IE) or Bookmark Bar (Chrome)
 4. In Edge, go to Settings > Show the favorites bar > On
 5. Import from another browser - choose either IE or Chrome
 6. In Edge.  Once import is complete, drag the bookmarklet into the Favourite Bar.  I also deleted other favourites that I didn't need from the import.

7. You now have a Lastpass bookmarklet!

 

Summary

This works for Twitter and Reddit

I also hope as Favourites gets synchronized across Universal Windows Devices - this should work on Xbox One and Windows Mobile 10 as well.

 

 

 

 

Thinking with JS Promise and Promises

 

Here's a real life example of a quick design iteration that we went through with promises this week.

In AngularJS (but this applies to any JavaScript), we have a function that calls the server to do a long running process.

function longProcess() {
    // dataservice returns a promise and we return that to our caller.
    return dataservice.longservice();
}

As this could potentially take nearly a minute, we want to add a waiting dialog.

AngularJS UI provides a modal dialog service $modal

function longProcess() {
  // create dialog
  var dialog = $modal.open({ templateUrl: 'wait.html' });

  var promise = dataservice.longservice();

  promise.then(
    function(){
      // success
      dialog.close();
    },
    function() {
      // fail
      dialog.close();
    }
  );
  return promise;
}

 

This works great.
But sometimes, the dialog flashes past too fast!  While the user is still trying to read it, it disappears.

Before we run off into code, let's stop a do a bit of thinking.

What we need is to combine the original promise, with a second new timer promise (of say 5seconds).  When both the service call has finished and the timer is up, we will resolve the promises.

So in pseudo code, it'd look like:

var p1 = service();
var p2 = $q.timer(5000);
var all = $q.all([p1,p2]);
all.then( /* resolve */ );

Note: $q is AngularJS' lightweight implementation of a Promise/A library Q.  The pseudo-code assumption was that $q would provide a timer-based promise that detonates once time is up.  In reality, $q doesn't provide such a method.  But the $timeout service in AngularJS returns a promise for exactly this scenario.

 

function longProcess() {
  var dialog = $modal.open({ templateUrl: 'wait.html' });

  var p1 = dataservice.longservice();
  var p2 = $timeout(angular.noop, 5000);
  var arrayOfPromises = [p1, p2];
  var promises = $q.all(arrayOfPromises);
  promises.then(
    function(){
      // success
      dialog.close();
    },
    function() {
      // fail
      dialog.close();
    }
  );

  // returns a combined promise to our caller.
  return promises;
}

 

Summary

The dialog opens and shows wait.html - it closes when the service is complete and when the timer has hit 5 seconds.