Outlook add in (calendar event): Series Id when editing "single event and the following" - outlook-web-addins

I have an Outlook addin for calendar events (Office 365 Web), which has a taskpane to show info for the user.
I have a problem when I edit a recurrence event, "this event and the following".
These are my steps:
I open an event on day_1, and set a 'daily' recurrence for 3 days [day_1, day_2, day_3].
Then I open my taskpane and I can read the id from Office.context.mailbox.item:
item1_id
and the recurrence info:
{"recurrenceProperties":{"interval":1},"recurrenceType":"daily","recurrenceTimeZone":{...},"seriesTime":
{"startYear":2020,"startMonth":10,"startDay":27,"endYear":2020,"endMonth":10,"endDay":29,"startTimeMinutes":600,"durationMinutes":30}
}
Then I save the event in the calendar.
A) If I open "all the series" to edit I read from the Office.context.mailbox.item:
seriesId: null
itemId: seriesId (=item1_id, saved value when series created --> I
know it is my series)
B) If I open a single event to edit, I read:
seriesId: seriesId (=item1_id, saved value when series created --> I know it is an event from my series)
itemId: itemB
C) If I open to edit "day_2 and the following", I read:
seriesId: null (it is correct?)
itemId: itemC ( I don't know this event is from the series I created...)
My code:
Office.onReady(info => {
g_item = Office.context.mailbox.item;
g_itemId = g_item.itemId;
if (g_itemId === null || g_itemId == undefined) {
g_item.saveAsync(function (result) {
g_itemId = result.value;
g_item.recurrence.getAsync((asyncResult) => {
if (asyncResult.status !== Office.AsyncResultStatus.Failed) {
g_recurrence = asyncResult.value;
console.log("Recurrence: " + JSON.stringify(g_recurrence));
console.log("ITEM ID: " + g_itemId);
console.log("SERIES ID: " + g_item.seriesId);
}
});
});
}
else
console.log("**** itemId found: " + g_itemId);
});
I hope you can understand my problem...
Thanks,
Diego

Related

Chrome extension for selected text which matches a specific form [duplicate]

I am trying to create entries on the Chrome context menu based on what is selected.
I found several questions about this on Stackoverflow, and for all of them the answer is: use a content script with a "mousedown" listener that looks at the current selection and creates the Context Menu.
I implemented this, but it does not always work. Sometimes all the log messages say that the context menu was modified as I wanted, but the context menu that appears is not updated.
Based on this I suspected it was a race condition: sometimes chrome starts rendering the context menu before the code ran completely.
I tried adding a eventListener to "contextmenu" and "mouseup". The later triggers when the user selects the text with the mouse, so it changes the contextmenu much before it appears (even seconds). Even with this technique, I still see the same error happening!
This happens very often in Chrome 22.0.1229.94 (Mac), occasionally in Chromium 20.0.1132.47 (linux) and it did not happen in 2 minutes trying on Windows (Chrome 22.0.1229.94).
What is happening exactly? How can I fix that? Is there any other workaround?
Here is a simplified version of my code (not so simple because I am keeping the log messages):
manifest.json:
{
"name": "Test",
"version": "0.1",
"permissions": ["contextMenus"],
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["content_script.js"]
}],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
content_script.js
function loadContextMenu() {
var selection = window.getSelection().toString().trim();
chrome.extension.sendMessage({request: 'loadContextMenu', selection: selection}, function (response) {
console.log('sendMessage callback');
});
}
document.addEventListener('mousedown', function(event){
if (event.button == 2) {
loadContextMenu();
}
}, true);
background.js
function SelectionType(str) {
if (str.match("^[0-9]+$"))
return "number";
else if (str.match("^[a-z]+$"))
return "lowercase string";
else
return "other";
}
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
console.log("msg.request = " + msg.request);
if (msg.request == "loadContextMenu") {
var type = SelectionType(msg.selection);
console.log("selection = " + msg.selection + ", type = " + type);
if (type == "number" || type == "lowercase string") {
console.log("Creating context menu with title = " + type);
chrome.contextMenus.removeAll(function() {
console.log("contextMenus.removeAll callback");
chrome.contextMenus.create(
{"title": type,
"contexts": ["selection"],
"onclick": function(info, tab) {alert(1);}},
function() {
console.log("ContextMenu.create callback! Error? " + chrome.extension.lastError);});
});
} else {
console.log("Removing context menu")
chrome.contextMenus.removeAll(function() {
console.log("contextMenus.removeAll callback");
});
}
console.log("handling message 'loadContextMenu' done.");
}
sendResponse({});
});
The contextMenus API is used to define context menu entries. It does not need to be called right before a context menu is opened. So, instead of creating the entries on the contextmenu event, use the selectionchange event to continuously update the contextmenu entry.
I will show a simple example which just displays the selected text in the context menu entry, to show that the entries are synchronized well.
Use this content script:
document.addEventListener('selectionchange', function() {
var selection = window.getSelection().toString().trim();
chrome.runtime.sendMessage({
request: 'updateContextMenu',
selection: selection
});
});
At the background, we're going to create the contextmenu entry only once. After that, we update the contextmenu item (using the ID which we get from chrome.contextMenus.create).
When the selection is empty, we remove the context menu entry if needed.
// ID to manage the context menu entry
var cmid;
var cm_clickHandler = function(clickData, tab) {
alert('Selected ' + clickData.selectionText + ' in ' + tab.url);
};
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if (msg.request === 'updateContextMenu') {
var type = msg.selection;
if (type == '') {
// Remove the context menu entry
if (cmid != null) {
chrome.contextMenus.remove(cmid);
cmid = null; // Invalidate entry now to avoid race conditions
} // else: No contextmenu ID, so nothing to remove
} else { // Add/update context menu entry
var options = {
title: type,
contexts: ['selection'],
onclick: cm_clickHandler
};
if (cmid != null) {
chrome.contextMenus.update(cmid, options);
} else {
// Create new menu, and remember the ID
cmid = chrome.contextMenus.create(options);
}
}
}
});
To keep this example simple, I assumed that there's only one context menu entry. If you want to support more entries, create an array or hash to store the IDs.
Tips
Optimization - To reduce the number of chrome.contextMenus API calls, cache the relevant values of the parameters. Then, use a simple === comparison to check whether the contextMenu item need to be created/updated.
Debugging - All chrome.contextMenus methods are asynchronous. To debug your code, pass a callback function to the .create, .remove or .update methods.
MDN doc for menus.create(), 'title' param
You can use "%s" in the string. If you do this in a menu item, and some text is selected in the page when the menu is shown, then the selected text will be interpolated into the title.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/create
Thus
browser.contextMenus.create({
id: 'menu-search',
title: "Search '%s'", // selected text as %s
contexts: ['selection'], // show only if selection exist
})

Outlook addin (calendar event): Recurrence is the previous one after changed

I have an Outlook addin (Office 365 Web) and I need to get the event recurrence when my taskpane is open.
I am using Office.context.mailbox.item.recurrence.getAsync() in the 'Office.onReady' method, but the recurrence value if I change it while the taskpane is open is the previous one.
TEST A: Recurrence and taskpane open/close
Create a 'New event'
Change the recurrence ('daily')
Open the taskpane and read the recurrence in the 'Office.onReady()' method
g_item.recurrence.getAsync --> Recurrence: valid value ('daily') // OK!
Close the taskpane
Open the taskpane and read the recurrence in the 'Office.onReady()' method
g_item.recurrence.getAsync --> Recurrence: valid value ('daily') // OK!
Close the taskpane
Change the recurrence (to 'weekly')
Open the taskpane and read the recurrence in the 'Office.onReady()' method
g_item.recurrence.getAsync --> Recurrence: previous value ('daily') // ERROR??
*** If 'no recurrence' when taskpane 1st open, close taskpane, change recurrence (to any) and open taskpane again --> Recurrence: null
My 'onReady' method:
Office.onReady(info => {
g_item = Office.context.mailbox.item;
if (!g_item.itemId) {
g_item.saveAsync(function (result) {
g_item.recurrence.getAsync((asyncResult) => {
if (asyncResult.status !== Office.AsyncResultStatus.Failed)
console.log("Recurrence: " + JSON.stringify(asyncResult.value));
});
});
}});
TEST B: Sync handler and button
I add a sync handler and a button. In the 'onReady' method:
Office.context.mailbox.item.addHandlerAsync(Office.EventType.RecurrenceChanged, handler);
document.getElementById("button").onclick = onClick;
Then, with the taskpane open:
Change recurrence from 'daily' to 'weekly' and Change event subject --> Recurrence handler is called TWICE:
a) OLD recurrence value ('daily') // ERROR?
b) NEW value ('weekly') // OK!
My handler method:
function handler(eventarg) {
console.log("handler. recurrence: " + JSON.stringify(eventarg.recurrence));
}
Press my button. Recurrence trace has the OLD value ('daily'), but subject trace has the NEW value (like the other values from the item but the recurrence...)
function onClick() {
g_item.recurrence.getAsync((result) => {
// Recurrence: previous value ('daily') ERROR!
if (result.status === Office.AsyncResultStatus.Succeeded)
console.log("onClick. Recurrence: " + JSON.stringify(result.value));
});
g_item.subject.getAsync((result) => {
// Subject: ALWAYS printed properly when changed!!!
if (result.status === Office.AsyncResultStatus.Succeeded)
console.log("onClick. Subject: " + JSON.stringify(result.value));
});
}
*** If recurrence is selected and THEN taskpane is open, onClick method read the value properly.

Getting users job title in Sharepoint List

So I have a SP Online list, that every user can submit his entries. I have a default column of "created by", where the user, that submited the entry is listed. I'd like to have 2 other columns, to get users Department and Job Title copied automatically from users account. How can I do this?
Method 1:
You can use the JSOM to set the Department/JobTitle. Because we don't sure where your user from(AD or some else )
First of all you need to load the “SP.UserProfiles.js, SP.Runtime.js and SP.js” js files on your SharePoint page, use following code snippet to load these files,
$(document).ready(function () {
var scriptbase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js",
function () {
$.getScript(scriptbase + "SP.js",
function () {
$.getScript(scriptbase + "SP.UserProfiles.js", GetUserInformation);
});
});
});
var userProfileProperties;
function GetUserInformation() {
// Get the current client context.
var clientContext = SP.ClientContext.get_current();
//Get Instance of People Manager Class
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
var targetUser = "domain\\userId";
userProfileProperties = peopleManager.getPropertiesFor(targetUser);
//Execute the Query.
clientContext.load(userProfileProperties);
clientContext.executeQueryAsync(onSuccess, onFail); }
function onSuccess () {
// get user information from userProfileProperties and set to your target column.
userProfileProperties.get_userProfileProperties()['Department'];
userProfileProperties.get_userProfileProperties()['SPS-JobTitle'];
// To do: list item replace operation
}
function onFail (sender, args) {
alert("Error: " + args.get_message());
}
Reference:https://msdn.microsoft.com/en-us/library/office/jj679700.aspx
Method 2: Workflow
When user add/edit a item,we trigger the workflow to copy the user's department/JobTitle to target column
Reference for get the Department/Jobtitle.
https://sharepoint.stackexchange.com/questions/97971/get-current-user-information-and-add-to-email-action-in-workflow

Data validation before next dialog waterfall step in Bot Framework

Have simple waterfall dialog:
SendMessageDialog = [
function (session) {
builder.Prompts.time(session, "Enter dates?");
},
function (session, results) {
session.conversationData.start = builder.EntityRecognizer.resolveTime([results.response]).toISOString();
if(typeof results.response.resolution.end != "undefined")
session.conversationData.end = results.response.resolution.end.toISOString();
}
];
Bot successfully recognizes time in different formats, and if format is invalid makes default prompt to user proposing to re-enter data like:
I didn't understand. Please choose an option from the list.
In Prompts option I can only change this default retryPrompt message. What if I need additional validation like:
User enters a date, but the date isn't valid because of business
logic (in the past, unavailable)
User enters a location, so need to check against list of available locations (perhaps from an api call)
Check number range after Prompts.number()
etc
Is there is an easy way to add additional validation to retry same waterfall step and ask user to re-enter data? How to implement this? Is there a workable code for BotBuilder 3.9?
There are some examples exist to make some validations with LUIS API calls, however they work only on next waterfall step. Goal not to go to the next step until correct data entered - is it possible? Thanks!
Right after the question was asked, had found how-to Create custom prompts to validate input:
Result code:
[
function (session) {
// Call start/end time prompt dialog
session.beginDialog("DatePromptDialog");
},
...
]
DatePromptDialog = [
function (session, args) {
var options = { retryPrompt: "I didn’t recognize dates you entered. Please try again using format: start - end dates" };
if (args && args.reprompt && args.endTimeMissed) {
builder.Prompts.time(session, "Please specify both start - end times:", options);
} else if (args && args.reprompt && args.dateInPast){
builder.Prompts.time(session, "That date seems to be in the past! Please enter a valid date.", options);
} else {
builder.Prompts.time(session, "Enter dates?", options);
}
},
function (session, results) {
var args = {};
delete session.conversationData.start; // Clear previous values
delete session.conversationData.end;
// Get start time
session.conversationData.start = builder.EntityRecognizer.resolveTime([results.response]).toISOString();
// Get duration end time if available
if(typeof results.response.resolution.end != "undefined")
session.conversationData.end = results.response.resolution.end.toISOString();
else {
args.endTimeMissed = true;
args.reprompt = true;
}
// Convert dates from string
var currDate = new Date(); // Current date
var startDate = new Date(session.conversationData.start);
var endDate = new Date(session.conversationData.end);
if(startDate < currDate || endDate < currDate) {
args.dateInPast = true;
args.reprompt = true;
}
if (args.reprompt) {
// Repeat the dialog
session.replaceDialog('DatePromptDialog', args);
} else {
// Success
session.endDialog();
}
}
];

Multiple Tab Chrome Extension Issue

I've created a basic extension that searches Google if the URL/HTML content fulfill certain requirements. It works for the most part, but fails miserably when there are multiple instances of the extension. For example, if I load tab A and then tab B, but click on the page action for tab A, I will be directed to a search of tab B's content.
I don't know how to silo the script to each tab, so that clicking tab A's page action will always result in a search for tab A stuff. How can that be done? I'd appreciate your suggestions!
background.js
title = "";
luckySearchURL = "http://www.google.com/search?btnI=I%27m+Feeling+Lucky&ie=UTF-8&oe=UTF-8&q=";
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.title != "") {
title = request.title;
sendResponse({confirm: "WE GOT IT."});
}
});
chrome.tabs.onUpdated.addListener(function(tabId, change, tab) {
if (change.status === "complete" && title !== "") {
chrome.pageAction.show(tabId);
}
});
chrome.pageAction.onClicked.addListener(function(tab) {
chrome.tabs.create({url: luckySearchURL + title})
})
contentscript.js
function getSearchContent() {
url = document.URL;
if (url.indexOf("example.com/") > -1)
return "example";
}
if (window === top) {
content = getSearchContent();
if (content !== null) {
chrome.runtime.sendMessage({title: content}, function(response) {
console.log(response.confirm); })
};
}
You could do something like store the title with its associated tabId, that way when you click on the pageAction it uses the correct title. The changes would be just these:
background.js
title= [];
[...]
chrome.runtime.onMessage.addListener(function(request,sender,sendResponse){
if (request.title != "") {
title.push({tabId:sender.tab.id, title:request.title});
sendResponse({confirm: "WE GOT IT."});
}
});
[...]
chrome.pageAction.onClicked.addListener(function(tab) {
title.forEach(function(v,i,a){
if(v.tabId == tab.id){
chrome.tabs.create({url: luckySearchURL + v.title});
// Here I am going to remove it from the array because otherwise the
// array would grow without bounds, but it would be better to remove
// it when the tab is closed so that you can use the pageAction more
// than once.
a.splice(i,1);
}
});
});
You're facing this issue because of window === top. So your title variable gets its value from the last opened tab. So if B is opened after A, title gets its value from B. Try this: Detect Tab Id which called the script, fetch the url of that tab, which then becomes your title variable. As below:
chrome.pageAction.onClicked.addListener(function(tab) {
chrome.tabs.query({active:true},function(tabs){
//this function gets tabs details of the active tab, the tab that clicked the pageAction
var urltab = tabs[0].url;
//get the url of the tab that called this script - in your case, tab A or B.
chrome.tabs.create({url: urltab + title});
});
});

Resources