Save functionality in Excel Addin using OfficeJs and ReactJS - excel

Background: I am developing an excel Add-in using OfficeJS library. The addin is using the ReactJS components and Office Fabric UI. The Add-in is successfully created and using OfficeJS library we can bring the user selection to the Excel sheet.
Problem: The problem is that I want to get the event in OfficeJS to Save the sheet using the Excel Native capability i.e., once user clicks on Save then the Save Dialogue box will appear(as per Native excel behavior)and on that I want to invoke my ReactJS business rules(some functionalities). In order to do that I want to use Save event for the same in OfficeJS which should be triggered automatically.
Code Sample:
Office.initialize = () => {
Excel.run(function (context) {
var sheet = context.workbook.worksheets.getItem("Sheet1");
context.workbook.load(["save"]);
context.sync().then(() => {
context.workbook.save(Excel.SaveBehavior.prompt);
//OR
context.workbook.save(Excel.SaveBehavior.save);
});
}).catch(function(error) {
console.log(error.debugInfo);
});
}
Research: The above two functions which I have tried are from the Microsoft Documentation where it is mentioned as:
Workbook.save saves the workbook to persistent storage. The save method takes a single, optional saveBehavior parameter that can be one
of the following values:
Excel.SaveBehavior.save (default): The file is saved without prompting the user to specify file name and save location. If the file
has not been saved previously, it's saved to the default location. If
the file has been saved previously, it's saved to the same location.
Excel.SaveBehavior.prompt: If file has not been saved previously, the
user will be prompted to specify file name and save location. If the
file has been saved previously, it will be saved to the same location
and the user will not be prompted.
System Configurations: I am using Windows 10, Excel 2016 Desktop and Office 365 Online version. I am using IE-10 and Google Chrome for Online version of Excel. Additionally I have checked the same using Windows-7 and Excel-2016 and same browsers.
Do let me know if the above functionality can be achieved?

Unfortunately, Office JS Excel API currently doesn't support onSaved event. one of the reasons was that Excel has an autosave feature, which triggers save action frequently. So we worry to provide onSaved event may fire too many event notifications to customers.
But I would suggest that you could submit the request and upvote this request at uservoice

Related

Open document from share point directly in office365

I'm using the graph API to access the documents in SharePoint. The response I'm getting looks like this:
graph api response
I want to let the user open this file (an excel file in this example) using excel desktop app. In other words, I want to resemble in my app the "Open in desktop app" functionality Excel for the web already provides:
excel for the web functionality
Is that possible?
Thanks in advance!
You can try and get the webUrl of the parent folder of the document you want to open. On that webUrl you add:
String documentUrl = parentWebUrl + "/YourDocumentName.docx";
And then you use Office URI scheme to open it localy (read more here)
It should be possible to do it using the webUrl of the document itself, but i have not figured out how to do it.

Automatically open Office documents on a Sharepoint Server 2013 in Firefox (full Office integration)

I recently switched to Firefox. Unfortunately my company still uses Sharepoint Server 2013 (migration to Sharepoint Online is planned somewhere in the future) which no longer offers a fluid integration with Office.
Every time I want to edit an Office document, it gets downloaded instead of being 'forwarded' to be opened by Word, Excel, etc. Modifications need to be saved locally and than uploaded afterwards. This is hugely annoying.
Is there some way that I can automate this in code, using a Firefox extension? Does Sharepoint expose some kind of hook or metadata containing the document's URL?
(Self-answer originally provided by Dotsoltecti; copied from question body into a proper answer).
Sharepoint 2013 passes the document's URL via the right-click contextual menu.
There exists a very neat add-on for Firefox called "custom right-click menu" by Sander Ronde. After installing this extension I added the script below:
var feedback = crmAPI.getClickInfo();
var url = feedback.linkUrl;
if (url.endsWith("docx") || url.endsWith("doc")) { var uri = "ms-word:ofe|u|" }
if (url.endsWith("xlsx") || url.endsWith("xls")) { var uri = "ms-excel:ofe|u|" }
if (url.endsWith("pptx") || url.endsWith("ppt")) { var uri = "ms-powerpoint:ofe|u|"}
var toOpen = uri.concat(url);
window.open(toOpen);
Et voilĂ : right clicking on a Word/Excel/PowerPoint-document executes the script and correctly forwards the document to the said program (you have to whitelist your SharePoint-site with the pop-up blocker). Modifications are handled directly by the Office-program.
Only drawback so far is that every time a document is opened, a new blank window is generated. I haven't found a solution for that yet, so suggestions are always welcome.

Intermittent behavior in xpages application: by pressing the button to save, the document is not redirected and is displayed again

I'm having a problem with a new xpages application that was deployed in production for a few months, but has now only been expanded to the entire enterprise now. The problem that did not happen while the application was in production pilot is intermittent and happens when an action executes a current notesxsppdocument save (currentdocument). The symptom is that by pressing the button you save, the document is not redirected and is displayed again. What can be this problem. session timeout, a bug from xpages? The application basically uses the components of the extension library, there is no external component to the xpages. When the problem occurs, if the user closes the document's xpages opens again and then clicks the button again the code runs successfully.
I have a function that stores a file attached to the doc in a repository. I suspect she's the problem. The function uses the file upload component and a button to execute a java agent that stores the file in a repository. The button code below follows. Its function is basically to create the rich text if it does not exist and call the agent that consumes a web service to transfer the file to a repository and erase it from the document.
I asked the user not to use the function for a few days at the time of the service to verify that the problem will persist.
if(validaArquivo())
{
var url=#ReplaceSubstring(context.getUrl(),"openDocument","editDocument")
url += '&tab=dossie' ;
var fieldItem:NotesItem =
currentDocument.getDocument().getFirstItem("arquivos");
if (fieldItem==null){
// create the field as an RTF
//writeToLog("Creating xxxxx field");
var rtItem:NotesRichTextItem =
currentDocument.getDocument().createRichTextItem("arquivos");
currentDocument.save();
}else if (fieldItem.getType()==1280){
//writeToLog("--> Converting xxxxx to RTF");
currentDocument.replaceItemValue("arquivosTEXT",
fieldItem.getText());
fieldItem.remove();
var rtItem:NotesRichTextItem =
currentDocument.getDocument().createRichTextItem("arquivos");
currentDocument.save();
}
var agente:NotesAgent=database.getAgent("(SalvaAnexos)");
agente.runWithDocumentContext(currentDocument.getDocument(true));
context.redirectToPage(url)
}
else
{
document1.removeAllAttachments("arquivos");
}
When users are using the application, rebuild or to change some code on prod environment can cause this.

Excel VBA Disable message "Uploading to..." when saving to Sharepoint

We have developed a client / server solution in Excel 2010 VBA. The Excel Database is hosted on a hidden document library on a SP 2013 Server. The client is a local workbook containing the data entry form.
We want to maintain secret the path to the hosted DB. The issue is that whenever the user commit changes via a dedicated VBA routine a pop-up message with title "Uploading to the server" is displayed with in message body: "Uploading..." and the full path of the server DB.
We have included all standard message disabling functions in Excel VBA:
Application.DisplayAlerts = False
and
Application.ScreenUpdating = False
but they do not have effect on this type of messages. Wondering if they are actually from Excel? They may come from IE or WebDAV? In any case they are displayed only when saving is taking some time.
The SP hosted DB is opened and closed as follows:
Workbooks.Open \OurIntranet\services\ContractsDatabase_hidden_\LIVE_DB\Database v01.04.xlsb, , False, , MyPwd
Application.DefaultSaveFormat = xlWorkbookNormal
UPDATING LINES -
wbk.Close
I have seen that also with DB hosted on a Network File Server the same message appears. So message box does not seem to be of SP origin.
Can someone help?
Thanks

Microsoft Dynamics CRM display error returned from plugin through javascript

I am using Microsoft Dynamics CRM (off premise)
Microsoft Dynamics® CRM Online Spring '14 (6.1.0.575)
Via the javascript SDK making a call to create an entity which fires off a plugin. We do our custom validations in the plugin in pre-validation.
Javascript create call example from here -> http://msdn.microsoft.com/en-us/library/gg334427.aspx
//Create the Account
SDK.REST.createRecord(
account,
"Account",
function (account) {
writeMessage("The account named \"" + account.Name + "\" was created with the AccountId : \"" + account.AccountId + "\".");
writeMessage("Retrieving account with the AccountId: \"" + account.AccountId + "\".");
retrieveAccount(account.AccountId)
},
errorHandler
);
And then I can handle the error using that errorHandler function, like this:
function errorHandler(error) {
writeMessage(error.message);
}
However, I am trying to get the error to display in the CRM error dialog box from InvalidPluginExecutionException. It displays it when I create the entity from a form, but when I make the call through javascript I can't seem to get it to display in the CRM error dialog box. I want to keep with the CRM theme, not use alert() in javascript, and have users be able to download the full exception that we are sending back.
Is it possible to call the dlg_error.aspx page in CRM and populate it with our error message? I am grasping at straws right now, anything would help out a lot. Thanks!
If you are using CRM 2013, I would suggest you to use Workflow instead of JavaScript to create record.
Create a new workflow and un-tick the checkbox "Run this workflow in backgroung (recommended)".
Create record from newly created workflow.
Save and publish the record.
Now go the the ribbon and select 'Run Workflow'.
Select the newly created workflow and click 'Add'.
If there is an error thrown by Plugin, It will be displayed in standard CRM Error dialog box which will allow you to download the log file.
You can try to execute a synchronous jQuery ajax method, without catching error and see what happens. Creating a record from jScript you are using RESTful endpoint of CRM service, I am not sure if the error is going to be promoted in the same way. Try to use Fiddler if you would like to try opening error dialog yourself. Using new synchronous workflow feature might also do the trick.

Resources