Для нашей надстройки мы используем следующий код, чтобы добавить пользовательскую категорию к текущей почте.Для этого мы используем Office REST API.И после этого мы также обновляем некоторые пользовательские свойства в электронном письме, которое мы используем позже.
Но по какой-то причине следующий код приводит к тому, что электронное письмо «изменяется».Это происходит только в клиенте Outlook для настольных ПК, а не в Интернете.
Мы сузили проблему, когда мы не обновляем пользовательские свойства, проблема исчезла ...
Следующий htmlфайл должен воспроизводить проблему, если вы используете его как index.html
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
<script src="//unpkg.com/@microsoft/office-js@1.1.8/dist/office.js"></script>
</head>
<body>
<div id="test"> Test </div>
<a href="#" onclick="javascript:setCategoryFunction();">Add category 'my custom category'</a>
</body>
<script>
Office.initialize = function(){
$("#test").html("test example");
// global function
window.setCategoryFunction = function(){
$("#test").html("loading...");
// get token
Office.context.mailbox.getCallbackTokenAsync({isRest:true },function(asyncResult){
$("#test").html("token result " + JSON.stringify(asyncResult));
if (asyncResult.status === "succeeded") {
var emailid = Office.cast.item.toItemRead(Office.context.mailbox.item).itemId.replace(/\//g, '-');
// This call to Office 365 REST API
$.ajax({
url : Office.context.mailbox.restUrl+"/v2.0/me/messages/"+emailid,
data : "{'Categories':['my custom category']}",
type : 'PATCH',
contentType : 'application/json',
processData: false,
dataType: 'json',
headers:{
"Authorization":"Bearer " + asyncResult.value,
'Content-Type': 'application/json'
}
}).done(function(response) {
// setting category via rest url works
$("#test").html("update mail result OK ");
// but then update custom properties...
Office.context.mailbox.item.loadCustomPropertiesAsync(function(responseProps){
var props = {};
props["customproperty"] = "mycustomprop_data";
var propsArray = responseProps.value.get("myprops") || [];
propsArray.push(props);
responseProps.value.remove("myprops");
responseProps.value.set("myprops",propsArray);
// Save all custom properties to server.
responseProps.value.saveAsync(function(){
$("#test").html("Now this e-mail is corrupt ??");
});
});
}, function(err){
$("#test").html("error:<br> " + JSON.stringify(response));
});
}
});
}
}
</script>
</html>