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?
Thanks for using the preview. Effectively as you mention, we made a few changes to some properties (namely obj.first, obj.last, obj.previous, obj.next were renamed to getFirst(), getLast(), getLast() and getPrevious() respectively in all the objects that support these functionalities.
If you install the latest insider slow build (16.0.7571.2006) or if you are in the insider fast builds, then you should see the changes working. The preview Office.js will be in sync with builds 16.7571+
Thanks and hope this clarifies what's going on..