I'm attempting to create a custom home page for Sharepoint 2013 which will operate similarly to the promoted links app - displaying all the apps installed by a user in a metro style interface.
The promoted links app works great, but my issue is that we want users to be able to install their own apps from the app catalog without having to edit the promoted links list to display it on the home page.
Is it possible to grab the url's / names of all the apps installed by a user from a web part?
The solution provided by Vadim is what I attempted first, but I found it did not return the apps installed. After a few trial and errors I discovered it was because I needed to look at the root web rather than the web where the app was installed.
So, in summary, my version is pretty much identical except for how the web is set:
web = ctx.get_site().get_rootWeb();
Use SP.AppCatalog.getAppInstances Method to retrieve AppInstance objects installed on an instance of SharePoint:
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var appInstances = SP.AppCatalog.getAppInstances(ctx, web);
ctx.load(appInstances);
ctx.executeQueryAsync(
function () {
//iterate apps
for(var i = 0; i < appInstances.get_count();i++) {
//...
}
} ,
function (sender, args) {
console.log(JSON.stringify(args));
});
Related
I want to get contact list from Android(If user open website in android). I was searching on it little bit. I found two question in stackoverflow similar to this.
Obtain Contacts Permission before Navigating (Cordova)
Listing phone contacts using javascript
Cordova
Here what I tried.
function onSuccess(contacts) {
alert('Found ' + contacts.length + ' contacts.');
};
function onError(contactError) {
alert('onError!');
};
// find all contacts with 'Bob' in any name field
var options = new ContactFindOptions();
options.filter = "Bob";
options.multiple = true;
options.desiredFields = [navigator.contacts.fieldType.id];
options.hasPhoneNumber = true;
var fields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
navigator.contacts.find(fields, onSuccess, onError, options);
I didn't get any error or alert message in android. When I visit the webpage in PC I got an error
Uncaught ReferenceError: ContactFindOptions is not defined
at contacts.php:17
I think I am having error cause, there's no contact function in PC.
I am so beginner in JS. I think Cordova must be installed in PC, I am not sure of the information also. If I have to than how can I install Cordova? I am using Debian Based Linux Distro. So, I tried
sudo apt-get install cordova
But,
E: Unable to locate package cordova
Are you building a mobile app with Cordova or are you just running your code in a website on Android?
If it’s just a website: you simply can’t do what you want since the browser doesn’t provide an interface to the contact list.
Unlike a Cordova app, which has access to the system APIs, among them the contact list API, JavaScript Code executed in a mobile browser, cannot access such APIs. The browser JS API simply provides no way.
JavaScript code run inside a Cordova/Capacitor mobile app however can Cordova APIs which bridge the mobile’s native API to JavaScript.
I am trying to deploy a Web App using Google AppScript with multiple views. I have an appCover.html with a few buttons and each button redirects to a different page. The app cover (or homepage) loads flawlessly but when I click on any of the buttons I get the error in the console:
Refused to display
'https://script.google.com/macros/s/sriptID/dev?v=newPage'
in a frame because it set 'X-Frame-Options' to 'sameorigin'
I have looked into Google's developer resources and all the references I found tell to add the XFrameOptionsMode.ALLOWALL. So I did but still no success. This is the function that is rendering each page:
function render(file, argsObject) {
var tmp = HtmlService.createTemplateFromFile(file);
if (argsObject) {
var keys = Object.keys(argsObject);
keys.forEach(key => {
tmp.key = argsObject[key];
});
}
return tmp.evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
}
Right now I am testing the deployment so I get /dev at the end when retrieving the URL and try to route with a parameter like /dev?v=newPage. Does it make a difference tying to access these pages when testing the deployment versus deploying itself?
It's a personal app so I'm the only user.
Any other ideas on how to solve this?
The problem is that you are using the dev version
Deploy your Webapp as an exec version
https://script.google.com/macros/s/XXX/scriptID
and then build your URL as
https://script.google.com/macros/s/sriptID/exec?v=newPage
Once you deploy your Webapp as a exec version, the method ScriptApp.getService().getUrl() will return you the corerct (exec) URL which you can use as a variable to dynamically build your redirection to different pages / views.
I'm building a new version of a Cordova project that uses the push notifications for the first time. I use the 'cordova-plugin-firebase' version 1.0.5 for handling them. Everything works fine on Android, but on iOS I seem to have a problem. If I download the official app from AppStore and then upgrade it with the new version via XCode, the push notifications doesn't seem to work (no "message" appears at the top in iOS). If I have the app opened, the XCode debugger prints the push notification and it looks like this:
{
"collapse_key" = "bundle_ID";
from = FIREBASE_ID;
notification = {
body = "This is a message";
title = "Message";
};
tap = 0;
}
If I then close the XCode project and create a new one (or open this newly created one again) with all source copied to it and the cordova plugins installed into and then build and install it via XCode, the push notifications start working again and the push notification in the XCode debugger looks like this:
{
aps = {
alert = {
body = "This is a message";
title = "Message";
};
};
tap = 0;
}
Should push notification formats differ? Has anyone experienced some similar behavior and how did you solve it?
It seems there was a bug or something in the iOS project. When I removed the ios platform and newly installed it everything started working and it still works until this day.
Also Apple's APS has different push notification object structure than Android's FCM.
I am currently working on a mobile app using version 1 of the Ionic framework. In this app I am using Google Maps to display a map. The map is being loaded using a script tag and works well while the device is connected to the internet. But if the app is started without an internet connection, the app won't even open. How can I solve this problem?
I am not sure why an Ionic app refuses to open at all when a library cannot be loaded, but luckily this issue can be solved.
TL;DR: You have to load Google Maps asynchronously, so check whether there is a network connection and if there is load the library and otherwise show an error.
There are many examples of how to load the Google Maps library asynchronously, like this post from Google, or this question which contains an answer to your question or this question in which the differences between loading using the script tag and loading asynchronously are explained. There is also this question in which it is shown using plain JavaScript.
Now of course that is a lot of text to go through, so here is the summary. Instead of adding a script tag in index.html, you have to load the Google Maps library only when there is an internet connection and load the library using JavaScript. In order to check for an active internet connection, you are going to need cordova-plugin-network-information, which you can find here. You can also use ngCordova to make it easier to use this plugin, you can find the documentation here.
In your controller, you can do something like this:
.controller('MapCtrl', function($state, $scope, $window, $ionicPlatform) {
// This view event is fired only when the view is loaded for the first time.
$scope.$on("$ionicView.loaded", function(scopes, states) {
var isMapLoaded = false;
var networkState = navigator.connection.type;
var isOnline = (networkState !== Connection.UNKNOWN && networkState !== Connection.NONE);
if(isOnline) {
// If there is a network connection, we load the map.
var mapsURL = 'https://maps.googleapis.com/maps/api/js?key=[INSERT API KEY HERE]&callback=';
$window.mapLoaded = function() {
isMapLoaded = true;
console.log("The map has been loaded.");
}
function loadMapsLibrary(url, callbackFunctionString) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url + callbackFunctionString;
document.body.appendChild(script);
}
$scope.isMapLoaded = isMapLoaded;
loadMapsLibrary(mapsURL, "mapLoaded");
} else {
// It's up to you what you do here, you can show an error for example.
}
In your view, you may have to use the ng-if directive and the isMapLoaded value to reload the <div> containing the map to ensure that it loads. This should give you a basic idea of what you need to do to get your app working again.
I'm trying to open a .exe application from WinJS but I get an error, this is my code:
var comando = "C:\\Program%20Files%20(x86)\\Windows%20Media%20Player\\wmplayer.exe";
var oShell = new ActiveXObject("Shell.Application");
//var commandtoRun = "C:\\Windows\\notepad.exe";
oShell.ShellExecute(comando, "", "", "open", "1");
but I get an error...
0x800A01AD - Runtime Error in JavaScript: Automation server can not
create object
any help I'll appreciate
I'm afraid it's not possible to use ActiveX controls in JavaScript Windows Store apps this way. Windows Store apps are isolated from the system and cannot run arbitrary code from outside the app container. It would be too easy to insert malware that way.
You can kind of pull it off if you know of a specific file type association. If you package a file with a file extension associated with the target app, you can tell your WinJS app to open it and it will trigger the associated app to open the file. Some obvious extensions are excluded, like .exe, .msi, etc.
This code will try to open a .txt file in whatever app is associated with that extension:
var txtFile = "Assets\\myFile.txt";
Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(txtFile).then(
function (file) {
Windows.System.Launcher.launchFileAsync(file).then(
function (success) {
if (success) {
// File launched
} else {
// File launch failed
}
});
});
It's not a perfect solution, as you cannot target a specific application, you can only trigger whatever app the user has associated with that file type, but it might be useful for some circumstances.