Posts Tagged With: CopyToDatabase

Copying a Sharepoint file using Flow

For one of the applications that we’re moving from Notes to the Microsoft platform, I need to copy documents from one Sharepoint site to another. There are two instances in which this task will be called: when a document gets approved for publication and when a project needs a new set of documents.

In Notes, I had a handle on how to do this. For the approved documents, my agent would send them via email to the destination database as a mail-in database. For creating a new set of documents, I would simply copy the main database and give it a new name. Needless to say, I liked my Notes solution a lot, but technology and user requirements are constantly changing.

This is a relatively simple thing, but I am again lost in the code. As in the past. I want to share my experience, so you can learn from it as well. Here’s what my copy file task looks like in Flow:

Copy File Image

So, we start with the assumption that there is a document, thisItem, being processed here, then have to direct Flow where to find it and provide the destination for the document. The trick was making sure to get Folder Path before File name with extension. I tried without using the path, thinking that Sharepoint docs would always be in the same directory (which they aren’t, of course!)

The other good news, beyond realizing I can do something in a different environment is that there actually is some “code” to look at. It’s not all just drag-and-drop, pretty pictures.

{
    "inputs": {
        "host": {
            "connection": {
                "name": "@parameters('$connections')['shared_sharepointonline']['connectionId']"
            }
        },
        "method": "post",
        "body": {
            "sourceFileId": "@{triggerBody()?['{Path}']}@{triggerBody()?['{FilenameWithExtension}']}",
            "destinationDataset": "https://mysite.sharepoint.com/sites/teams/oimt/TAMIS",
            "destinationFolderPath": "/Documents",
            "nameConflictBehavior": 1
        },
        "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://mysite.sharepoint.com/sites/Policy/PolicyPortal'))}/copyFileAsync",
        "authentication": "@parameters('$authentication')"
    },
    "metadata": {
        "flowSystemMetadata": {
            "swaggerOperationId": "CopyFileAsync"
        }
    }
}

It’s a small step, but one I’m happy to have accomplished and privileged to share.

Advertisements
Categories: Flow, Xpages | Tags: , , | Leave a comment

Copying design elements via script in #XPages

One of my first posts was about copying a view from one database to many using XPages. Well, as I was surfing the help documents to learn more about FTSearch in order to extend the capabilities of my Excel exporting capabilty, I found createNoteCollection.

createNoteCollection can be used to create a collection of all notes in a Notes database. That is, not just Notes documents, but all Notes design elements. Not only that, but you can quickly choose what kind of notes you want in your note collection. While there are boolean parameters for each type of note you might want, I am most intrigued by the combination ones, which allow you to select by category.

selectAllAdminNotes (ACL and replication formulas)
selectAllCodeElements (agents, database script, outlines, script libaries and misc code elemnts)
selectAllDataNotes (documents AND profile documents)
selectAllDesignElements (code, format, index, help, icons and shared fields)
selectAllFormatElements (actions, forms, framesets, image resources, java resources, misc format elements, pages, style sheets and subforms)
selectAllIndexElements (folders, misc index elements, navigators and views)
selectAllNotes (everything)

So, once you create  your note collection, then you can walk the collection using getFirstNoteID and getNextNoteID, accessing each design element (or document). Then, using NotesDatabase.getDocumentByID to get a handle to it as a NotesDocument, so you can use NotesDocument.CopyToDatabase to copy the design element across to the new database.

var db:NotesDatabase=database;
var notecollection:NotesNoteCollection=db.createNoteCollection();
notecollection.selectAllDesignElements();
var noteID:String=notecollection.getFirstNoteID();
var note:NotesDocument;
var nextNote:NotesDocument;
while ( noteID != null ) {
	note=db.getDocumentByID(noteID);
	if ( note != null ) {
		note.copyToDatabase();
	}
	noteID=notecollection.getNextNoteID();
	nextNote=db.getDocumentByID(noteID);
	note.recycle();
	nextNote=note;
}

Now, it is a little blunt to grab all design elements and copy them from one database to another. One problem is that you are certain to have some duplication of design elements and I’m sure that will create problems. I know that I was able to have two identically named views in my original post, so I didn’t copy the view if it already existed in the destination database. So, you might want to create collections in both databases and compare the design notes t0o make sure not to create duplicates (either by deleting the one in the destination database first or simply not copying the new one in).

Categories: Old Notes, Server-Side Javascript, Utilities, Xpages | Tags: , , | Leave a comment

Blog at WordPress.com.

%d bloggers like this: