0

I usually create OneNote APIs while looking at this site (https://learn.microsoft.com/ja-jp/javascript/api/onenote?view=onenote-js-1.1), but I'm having trouble with copyToNotebook().

It says that the argument is wrong, but I put a variable of type OneNote.Notebook as specified.

I can't do another copyToSection(destinationSection) either.

I get the same thing with the wrong argument, but it should be there.

Both use the exact same code as the sample code in the official reference.

What are some possible things that could be happening?

If not, what other code should I use to get the same behavior?

Thank you in advance.

Code

async function deleteInfo() {
    await OneNote.run(async (context) => {
        const app = context.application;
        // Gets the active Notebook.
        const notebook = app.getActiveNotebook();
        // Gets the active Section.
        const section = app.getActiveSection();

        let newSection;

        await context.sync();
        try {
            const newSection = section.copyToNotebook(notebook);
            newSection.load('id');
            await context.sync();
            console.log(newSection.id);
        } catch (copyError) {
            console.error(copyError);
            if (copyError.debugInfo) {
                console.error("Debug Info:", JSON.stringify(copyError.debugInfo, null, 2));
            }
            if (copyError.innerError) {
                console.error("Inner Error:", JSON.stringify(copyError.innerError, null, 2));
            }
        }
    });  
}

Error

Debug Info: {
  "code": "InvalidArgument",
  "message": "InvalidArgument",
  "errorLocation": "Section.copyToNotebook",
  "statement": "var copyToNotebook = v.copyToNotebook(...);",
  "surroundingStatements": [
    "var v = context.root._getObjectByReferenceId(\"{70f32172-415d-4679-abad-71d6bbbacf0b}{13}\");",
    "var v1 = context.root._getObjectByReferenceId(\"{70f32172-415d-4679-abad-71d6bbbacf0b}{12}\");",
    "// >>>>>",
    "var copyToNotebook = v.copyToNotebook(...);",
    "// <<<<<",
    "// Instantiate {copyToNotebook}",
    "copyToNotebook.load([\"id\",\"name\"]);"
  ],
  "fullStatements": [
    "Please enable config.extendedErrorLogging to see full statements."
  ]

Tried: Tried to track down the cause of the error with error handling, but could only find what was described in the problem description.

What I expected to happen: A section and a page within it can be created as a new section in the same notebook

What actually happened: InvalidArgument Error

1
  • If you don't get an answer from the community in a couple of days, I suggest that you create a bug report issue on the Office.js repo: github.com/OfficeDev/office-js/issues Commented Apr 24 at 17:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.