SDK Unused documents

2
Hi all,  I am trying to use the SDK to retrieve all Unused documents in my model, and then, for instance delete them (or exclude them) automatically.  Is there some example source code available, to retrieve these unused items, which I can use? Before I start to plunge myself into the deeps of typescript..  Thanks!
asked
2 answers
2

I'm not aware of such a script yet. I'm not even sure this information can be retrieved using the SDK.

Keep in mind that not all items are actually unused. For example microflows used by the excel importer.

answered
2

Found this while searching for a script to remove excluded items from my project, then ended up writing it myself. Here's an SDK script:

const client = new MendixPlatformClient();

const app = client.getApp("<appid>");

const workingCopy = await app.createTemporaryWorkingCopy("main");
const model = await workingCopy.openModel();

const allExcludedDocs = model.allDocuments().filter(d => d.excluded);

let doc;
for (doc of allExcludedDocs) {
    doc.delete();
}

await model.flushChanges();
await workingCopy.commitToRepository("main");

 

answered