I am trying to use Dialog API of Office Add-ins.
According to the doc, we could use Office.context.ui.messageParent to send a message from the Dialog box to the host page (eg, task pane). Whereas, I don't see how we could send a message from the host page to the Dialog box.
Does anyone know how to do this?
There are 2 possible solutions:
Send data as query params, when you open a pagein dialog box.
If there are in same domain then localstorage should be available in dialog which was opened.
setInterval(function () { var value = localStorage.getItem("dataFromDialog"); }, 500)
You can write the same value in localStorage in dialog localStorageSetItem("dataFromDialog", "message to parent")
This feature is now in preview
See https://learn.microsoft.com/en-us/office/dev/add-ins/develop/parent-to-dialog
Example from the post:
Office.context.ui.addHandlerAsync(
Office.EventType.DialogParentMessageReceived,
onMessageFromParent);
function onMessageFromParent(event) {
var messageFromParent = JSON.parse(event.message);
}
Related
I am trying to use Dialog box.
In my add-in, I have two buttons openGoogle and openStackoverflow which link to openDialog("https://www.google.com") and openDialog("https://www.stackoverlfow.com"):
function openDialog(url) {
Office.context.ui.displayDialogAsync(url, { height: 1100, width: 1000 },
function (result) {
console.log("here")
dialog = result.value;
}
)
}
First, I open one dialog by clicking on openGoogle, then if I click on openStackoverflow, here is displayed again, however the dialog does NOT go to stackoverflow.
Does anyone know what's wrong?
From the documentation:
the page, controller method, or other resource that is passed to the
displayDialogAsync method must be in the same domain as the host page.
If you need to get users to another domain, you can do this by first opening a dialog to a page within your add-in that then immediately redirects them to the external domain using window.location.href = "https://www.stackoverlfow.com";
I'm new to chrome extension development but I'm running into issues debugging and with the extension itself. I currently have a form with a submit button and after the user hits submit I change the html to show the data that was just submitted.
document.addEventListener('DOMContentLoaded', function() {
console.log("1");
document.getElementById("submitButton").addEventListener('click', myFunction);
console.log("2");
//getCurrentTabUrl(function(url) {
// renderStatus(url);
//});
});
function myFunction() {
document.getElementById("formOutput").innerHTML = document.getElementById("formInput").value;
alert("hi");
console.log("test");
);
}
In this, 1 and 2 are displayed to the extension debugging console and the alert runs as well when the button is clicked. The test shows up very briefly and then it disappears.The formoutput value changes very briefly as well and then changes back to the default value I have. Does anyone know why my code/the chrome extension would be doing this?
Thanks!
When button with type submit (This is the default if the attribute is not specified) is clicked, the form data will be sent to server and page will be redirected to new page. Then your content script will be injected again, that's why the it changes back to default value.
To avoid this, you could change button with other types, or calling e.preventDefault to prevent default behavior. Then you would want to use Ajax to send data to server, which ensure the whole page won't be redirected and only parts of UI can be updated.
how to send error message to user from agent when using xpages?
Here the detail engine:
1. The xpages contains a button. when the button was clicked then it will call the agent to process the context info
2. On processing the agent, is it possible to send warning message to user (dialog box)? If yes, What command for send it?
Thanks
An agent cannot directly interact with XPages. One method would be to write output to a control document and for XPages to pick up that control document and put the message in a requestScope variable to be displayed on the page.
I agree with Paul. Just adding a small snippet here for you to start:
var agentName:String = "agentName";
var agent:NotesAgent = database.getAgent(agentName);
if (agent != null)
{
var doc:NotesDocument = document1.getDocument() // assuming datasource name is document1
agent.runWithDocumentContext(doc);
/*
In your agent you process a document with particular form and say a unique id of the passed
document context
*/
var v:NotesView = database.getView("warningView"); // For eg. stored in a warning view
var warningDocument:NotesDocument = v.getDocumentByKey(doc.getUniversalID());
// You can process the document according to your needs then ( you can do later step after your dialog is opened)
}
else
{
// throw and error message
}
Hope this helps.
Chintan and Paul are correct. Using the technique described in this article you can capture all print output from an agent and use that in the XPage. However....
This is an excellent opportunity to pay down some technical debt and transform your agent into a bean. If it is well written, it should be easy. If its not, then you clean it up
I'm using Notes/Domino 8.5.3. I've added a button control to an xpage. The button uses a Confirm Action to display a client-side prompt to the user before continuing with the next action defined for the button. When I use static text for the Confirmation Text for the Confirm Action, the confirmation prompt is displayed. However, when I change the Confirmation Text to be computed, and retrieve the text from a profile document, the confirmation prompt it not displayed at all in XPiNC. The confirmation prompt with the computed confirmation text is displayed just fine in a browser. Is there a work-around for this issue with XPiNC?
Following is the code I'm using in the Confirm Action to get the text for the prompt:
var server = database.getServer();
var dbProfile:NotesDocument = database.getProfileDocument("DBProfile", "");
var msg = dbProfile.getItemValueString("ContactsInitUpdatePrompt");
return msg;
To further my comments, this is a work around I use the below code for an app that uses the bootstrap extension library on the web but uses basic functionality with xpinc.
If the values for xPinc are different you could make the confirm action different in the browser and in the client.
if (#ClientType()== "Notes")
{
<action>;
}
else{
<action>;
}
I think that profile documents are a bad idea in xPages though. Having to restart HTTP to get a new value ruins the point I think. Almost better to hard code values at that point. I think you can set application scope to handle the work of profile documents. But then application scope in xpinc is just on the current machine as the server is the client.
We're seeing some strange behavior with Facebook Send dialogs (Javascript SDK, FB.ui method). After the Send button is clicked, the dialog disappears, then reappears. The dialog does disappear after a while without any user action, but this delay varies (anywhere from a split second to several seconds).
The messages are delivered without problems.
How to reproduce:
https://apps.facebook.com/barclays_pingit/
Click on "Send Message" under the "Tell a friend" title
Add a recipient and message
Click "Send"
Or:
Click on "Make your own video"
Choose a friend, how much they owe you, and for what
Click "Make video"
You can skip to the end of the video, then click "Send video to ..."
Add a message Click "Send"
Does anyone have any ideas?
Sorry I can't give you the answer, but as I have the same problem, here is a quick patch:
var callback = function callback(response) {
var clear_callback = function(){
$('.fb_dialog').remove();
};
var arr = [250,1000,2000,3000,4000,5000,7000];
for (var i in arr)
{
setTimeout(clear_callback,arr[i]);
}
}
FB.ui(obj, callback);