I have created a taskpane addin for word that runs a search and will display the text for the first paragraph for the search result. Until a couple of days ago the following code was running successfully:
function onGetFirstRangeParaClick() {
var textToFind = "Word",
range,
paragraph;
return Word.run(function (context) {
var searchResults = context.document.body.search(textToFind, { matchWildCards: false });
context.load(searchResults, "text");
return context.sync()
.then(function () {
range = searchResults.items[0].getRange();
context.load(range, "text, paragraphs");
return context.sync();
})
.then(function () {
paragraph = range.paragraphs.first;
context.load(paragraph, "text");
return context.sync();
})
.then(function() {
$("#getFirstRangeParaResult").text(paragraph.text);
});
})
.catch(onError);
}
However now the following error is being thrown:
{"name":"OfficeExtension.Error","code":"GeneralException","message":"GeneralException","traceMessages":[],"debugInfo":{"errorLocation":"ParagraphCollection.first"},"stack":"GeneralException: GeneralException\\n at Anonymous function (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:8360:6)\\n at lib$es6$promise$$internal$$tryCatch (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9595:8)\\n at lib$es6$promise$$internal$$invokeCallback (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9605:8)\\n at lib$es6$promise$$internal$$publish (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9581:9)\\n at lib$es6$promise$asap$$flush (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9400:8)"}
I am using the debug PreviewCDN (//appsforoffice.microsoft.com/lib/beta/hosted/office.debug.js) and am running office version 1610 (Build 7466.2038)
I noticed in the Api documents that paragraphs.first
is changing to paragraphs.getFirst()
but it doesn't look like this is implemented yet as if I change to use getFirst()
I get the following error:
Object doesn't support property or method 'getFirst'
How should I be using first or getFirst() for a ParagraphCollection?