You are viewing limited content. For full access, please sign in.

Question

Question

insert line of text

asked on June 1, 2022

Hello,
I need to add a line of text at the end of the first page of a document in the repository in txt format, I have resorted to a script in workflow but without any result, since the next line replaces the entire content of the page.
' Retrieves the document and page from the repository
' and locks them for writing.
Dim Doc As LFDocument = DB.GetEntryByPath("\Start\Doc1")
Doc.LockObject(Lock_Type.LOCK_TYPE_WRITE)
Dim DocPages As LFDocumentPages = Doc.Pages
'Retrieves page 1.
Dim PageOne As LFPage = DocPages.Item(1)
' Gets the text object from the page.
Dim NewText As LFText = PageOne.Text
'Changes the string assigned to the text,
' saves the changes, and cleans up unused handles.
NewText.Text = "This page now has text on it."
NewText.Update()
Doc.Dispose()
 

0 0

Replies

replied on June 1, 2022

I have something similar in place, so I'll share that here in case it helps you.

I don't know if this is exactly what you are trying to do, but if I'm understanding correctly, this might work...

This is a C# script (whereas I believe you were sharing Visual Basic script) that takes in two tokens from the Workflow (the document that is being edited and the existing text on the first page of that document).  It then adds an extra line of text to the end of the document indicating the timestamp that the item was processed.

First - we have a "Search Repository" activity that finds the desired document, it is set to return "First Result", which results in this token: %(SearchRepository_FirstResult_ID)

Second - we have a "Retrieve Document Text" activity that takes in the entry from the "Search Repository" activity, and retrieves the text on page 1, which results in this token: %(RetrieveDocumentText_Text)

Third - we have an "SDK Script" activity with this code: 

using (DocumentInfo doc = Document.GetDocumentInfo((int)GetTokenValue("SearchRepository_FirstResult_ID"), this.RASession))
{

    //Retrieve the existing text
    var textString = GetTokenValue("RetrieveDocumentText_Text").ToString();

    //Add text about validation timestamp
    DateTime currentDateTime = DateTime.Now;
    textString = textString + "\nDocument Updated Timestamp: " + currentDateTime;

    //Update the text on page 1 of the entry.
    PageInfo PI = doc.GetPageInfo(1);
    PI.WriteTextPagePart(textString);
    PI.Save();

}

 

Ultimately, this is making use of the built-in activities to pull in the reference to the document and the existing text on page 1, so the script itself doesn't need to do much other than update the text and push it back into the document.

 

P.S. - please use the code button (says {...} and code on it) when posting code here on Laserfiche Answers in order to make it easier to read.

4 0
replied on June 3, 2022

Excellent Matthew and thank you very much

1 0
replied on June 6, 2022

You're welcome.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.