I have a Lotus Domino web application that uses plain old forms. The database already has some documents, and I want to clone one of the documents. So I thought that I could just issue an URL request like this:
/database.nsf/viewName?clone=12345678
This URL should open the form and prefill all form fields with those from the document with the ID 12345678. The user should then be able to edit all fields.
At which point can I intercept the form creation?
How do I access the newly created document that stores the form values?
Can I do all this in LotusScript, or do I have to use the formula language?
Just use an agent (Trigger: None). URL would be something like: /database.nsf/YourAgentname?OpenAgent&clone=12345678
In the agent you can get the parameter like this:
Dim ses as New NotesSession
Dim docParam as NotesDocument
Dim strQueryString as String
'- Get the parameter- document
Set docParam = ses.DocumentContext
'- get the querystring
strQueryString = docParam.getitemValue( "Query_String" )(0)
'- querystring will be OpenAgent&clone=12345678
'- here you can extract the id from the querystring
....
'- then you get the document (if 12345678 is the noteid e.g by db.GetDocumentByID( )
'- or if it is your own key by NotesView.GetDocumentbyKey()
Set docOrigin = ....
'- Now create a new doc
Set docClone = New NotesDocument( db )
'- Fill the fields
Call docClone.ReplaceItemValue( "Field1" , docOrigin.GetItemValue( "Field1" ) )
'- Or all at once
Call docOrigin.CopyAllItems( docClone )
'- Here is the trick: Redirect to the new document using the agent output:
Print "[/" & db.HttpURL & "/_/" & docClone.Universalid & "?EditDocument" & "]"
The Brackets make the browser directly redirect to that page...
This code was just written from "memory" and might contain Typos / logical errors, but it should be a good starting point...
Use ?OpenForm&ParenUNID=<unid> to prefill with values from document with <unid>.
Related
I'm using ADO because I want to write to a Sharepoint list using VBA in Excel.
Right now I am getting "The Microsoft Access database engine could not find the object 'Isaac Test Excel To Sharepoint', and the code errs on the INSERT line. I suspect it is because of either my site reference being wrong, or my list ID being wrong.
I don't think my list ID is wrong, because I carefully followed the directions to extract the list ID from the URL that's exposed when you go to List Settings, carefully Replacing the 3 replaceable items as mentioned here: https://community.nintex.com/t5/Community-Blogs/Obtaining-a-list-id-in-SharePoint-2010-or-2013/ba-p/77664#:~:text=Navigate%20to%20the%20list%20and%20click%20List%20Settings.,Guid%20Format%20with%20URL%20encoding).
I am passing it in as:
strSharepointListID = "{3404D534–10CB–4F53–BB9D–37F5612155F1}"
I would like to have concluded, "the connection is correct because the code doesn't err until all the way to the INSERT statement", but unfortunately I've proved that to be false: If I pass in a totally non-existent Site value, gibberish, the code still doesn't err until all the way at the INSERT statement.
The name of my list is definitely Isaac Test Excel To Sharepoint
The site I am passing is like this, with me sanitizing this by replacing some text with "text": (I've tried all 3 of these):
strSharepointSite = "https://text.text.text.com"
strSharepointSite = "https://text.text.text.com/sites/text"
strSharepointSite = "https://text.text.text.com/sites/text/_layouts/15/start.aspx#/"
Full code:
Sub Upd2KPIMember_SP()
Dim cnt As ADODB.Connection
Dim mySQL As String
Dim strSharepointListID As String, strSharepointSite As String
'https://community.nintex.com/t5/Community-Blogs/Obtaining-a-list-id-in-SharePoint-2010-or-2013/ba-p/77664#:~:text=Navigate%20to%20the%20list%20and%20click%20List%20Settings.,Guid%20Format%20with%20URL%20encoding).
'list ID from sharepoint URL:
' %7B3404D534%2D10CB%2D4F53%2DBB9D%2D37F5612155F1%7D
'list ID after replacing as follows:
' %7B3404D534%2D10CB%2D4F53%2DBB9D%2D37F5612155F1}
strSharepointListID = "{3404D534–10CB–4F53–BB9D–37F5612155F1}"
strSharepointSite = "[sanitized for SO post]"
Set cnt = New ADODB.Connection
With cnt
.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;DATABASE=" & strSharepointSite & ";LIST=" & strSharepointListID & ";"
.Open
End With
mySQL = "insert into [Isaac Test Excel To Sharepoint] (column1,column2) values ('col1_val1','col2_val1');"
cnt.Execute (mySQL)
If CBool(cnt.State And adStateOpen) = True Then cnt.Close
Set cnt = Nothing
End Sub
I'm also fairly sure the SQL syntax is good, because the code DID tell me when it was wrong--When at first I used INSERT TABLE instead of INSERT INTO TABLE.
Partial credit to KeshavSharma (see comments) for
correctly mentioning LIST ID not required, use LIST NAME instead
inspiring me to keep focusing on THAT line of code - that it was the problem
The final code that worked was precisely identical to the first code I posted, EXCEPT, inside the connection string, instead of:
LIST={8F7FEF30–C868–4480–8AC8–4FE4FDB3921A};
I need to use:
LIST=Isaac Test Excel To Sharepoint;
(despite spaces in object name - I need to use NO single quotes, NO brackets).
Very happy this got solved - hopefully it helps someone else some day.
We recently wrote some code for a client using the Aspose.pdf library, on my system the pdf in question opened fine and most of the merge fields were filled in (we don't have the exact list of merge fields that they do).
They're telling me that on their system, some documents take 2-4 mins to open while others don't open at all.
What could be a possible cause of the document not opening at all?
My code is below:
' Load form
Dim doc As Aspose.Pdf.Document = New Aspose.Pdf.Document(sTemplateDir & sDocName)
'Get names of form fields
Dim fields As Aspose.Pdf.InteractiveFeatures.Forms.Field() = doc.Form.Fields
Dim sField As String
Dim field As Aspose.Pdf.InteractiveFeatures.Forms.Field
If fields.Length > 0 Then
For Each field In fields
'Get name of field
sField = field.FullName
'If the merge field isn't valid then we'll just leave it and assume its a fill-in
If nMergeCol.Contains(sField) And Not IsNothing(sField) Then
field.Value = nMergeCol.Item(sField)
End If
Next
End If
This has been resolved! As we suspected, it was a problem with the client's Javascript within the pdf file. The problem was within the calculations the absolute value was being used (name.value). Once this was switched to the relative value (this.event.value) the pdf file began behaving correctly with the AsPose code.
I'm trying to save a Microsoft Word 2013 document with a specific filename.
I created a Word form that a client fills out.
I am using the following: DEVELOPER -> Controls -> Plain Text Content Control DEVELOPER -> Controls -> Date Picker Content Control DEVELOPER -> Controls -> Drop-Down List Content Control
I would like a macro to save the document with the name of one of the fields in the form.
Example:
below are fillable content fields.
client reference: A1B2-345
date: August 17, 2015
type: metadata
I would like to save the file as:
A1B2-345_17082015_metadata.DOCX
Start by giving each of your controls a Title. You can do this by clicking on your control in your document and then click Properties on the Developer ribbon. The first field on the Properties window is Title. Give each one of the controls you need to access a unique title. In the example below, I'm using MyText, MyDate, and MyDrop for the text, date, and drop-down controls, respectively.
Then you can access each control in VBA by using the SelectContentControlsByTitle() function. As long as you're using a unique title, this function will return a collection containing only a single control so we can just retrieve the first item from the collection (index (1)). Here's how this would look:
Dim strText As String, strDate As String, strDrop As String
strText = ThisDocument.SelectContentControlsByTitle("MyText")(1).Range.Text
strDate = ThisDocument.SelectContentControlsByTitle("MyDate")(1).Range.Text
strDrop = ThisDocument.SelectContentControlsByTitle("MyDrop")(1).Range.Text
The Range.Text ending is what grabs the current text/value from the control.
Now that you have your three pieces of information, you can concatenate them into one string using the concatenation operator (&):
Dim strFilename As String
strFilename = strText & "_" & Format(strDate, "ddmmyyyy") & "_" & strDrop & ".docx"
And, finally, save it:
ThisDocument.SaveAs strFilename
It should be noted that the code provided above will not work properly if you are generating the form based off a template (.dotm). The following lines that include the ThisDocument.SelectContentControlsByTitle need to be changed to
ActiveDocument.SelectContentControlsByTitle otherwise the code will pull the place holder text from the content control.
I'm a newbie writing my first app. I need help with the following: I need to retrieve the logged in user which = GID, I then need to append it to a URL which will start our Help Desk chat client. I can retrieve the GID easy enough but can't figure out how to append it and pass it with the URL. I found a post which instructed to declare the url as a string also and concatenate it. The UserName would follow the ":" at the end of the Url.
Private Sub GID()
Dim GID As String
GID = System.Environment.UserName
' System.Diagnostics.Process.Start("http://www.myurl.com/eschat/arhome.html?login=m:uid~uid:")
We use javascript to do this from the HelpDesk site, but I need to adapt it to work from my app. Any help would be appreciated and I hope my question makes sense.
You can concatenate strings in VB.NET using '&' like this:
Dim GID as String
GID = System.Environment.UserName
Dim URL as String
URL = "http://www.myurl.com/eschat/arhome.html?login=m:uid~uid:"
System.Diagnostics.Process.Start(URL & GID)
You can also insert the variable into the string like this
URL = String.Format("http://www.myurl.com/eschat/arhome.html?login=m:uid~uid:{0}", GID)
and the GID will be placed wherever the "{0}" is, this can also be used for multiple parameters, you just increment the number inside the curly braces e.g. "{1}", "{2}".
MSDN article here.
Need a way to connect to a unique SQL db via login in ASP classic.
THE SETUP
Webapp: ASP classic/SQL 2005.
Webapp stores information for multiple companies.
All data stored in one master SQL 2005. All db's will be on same server.
Each user has a unique login (Company, User ID, Password)
Connection is with master db include file using DSN-less connection
IE: (dbConn.Open "driver={SQL Server};server=11.22.333.444;database=mywebdb","mylogin","mypassword")
THE NEED:
Want to split companies into their own database. When the user logins, the company name will tell the APP to use a unique SQL db connection for each company.
Since dynamic include files are not an option, what is best route to go?
Thank you!
The connection string must be stored some where right? A include .asp I guess.
Add code in that include to examine the company name (stored in the session?) and fixup the connection string accordingly.
Edit:
The issue is you may have code out there in a myriad different ASP pages that assumes the appropriate connection string is available in a variable declared in you db.asp include file (lets call it m_connStr). You don't want to have to modify all these pages in order to meet this new requirement.
Thus you only want to edit the db.asp include file and you just want m_connStr to magically point at the correct DB.
Have your logon page once you know the company set the database name in a Session variable.
Your existing code has the connection string like this:-
m_connStr = "driver={SQL Server};server=11.22.333.444 database=mywebdb", "mylogin", "mypassword"
So we'll use a template:-
m_connStrTemplate = "driver={SQL Server};server=11.22.333.444 database=%db%", "mylogin", "mypassword"
If Session("database") <> "" Then
m_connStr = Replace(m_connStrTemplate, "%db%", Session("database"))
End If
Note a non-existant database session variable causes the connection string to not be defined hence you can't accidentally connect to a default database.
Now as far as all your ASP pages are concerned it's business as usual but the connection string will vary by session according to the company associated with the logged on user.
However you do it, you'll end up varying your connection string based on user input. Don't use user input directly, but validate it against a list of acceptable values. I suggest a Select Case statement to do this:
' Do this when logging in: '
Dim companyName
companyName = Request.Form("companyName")
Select Case companyName
Case "company1"
Session("companyDB") = "company1"
Case "company2"
Session("companyDB") = "company2"
Case Else
Session.Contents.Remove("companyDB")
' Invalid login! '
End Select
' Do this when connecting to the database: '
Dim connectionString
If Session("companyDB") Then
connectionString = "...database=" & Session("companyDB") & "..."
Else
' Invalid login, go log in again '
End If
Keep in mind that this will lead to trouble if you have users who will want to open one company in one tab and another company in another tab. They are going to wonder why they can only see information for the company they logged into most recently.
If this is going to be an issue, you will probably want to pass a token around in the query string on each link. This adds complexity, but not terribly much (aside from the tedious task of changing every link). It would then look like this:
' Do this when logging in: '
Dim companyName
companyName = Request.Form("companyName")
Select Case companyName
Case "company1"
Session("company1 - db") = "company1DBName"
Case "company2"
Session("company2 - db") = "company2DBName"
Case Else
' Invalid login! '
End Select
' Do this when connecting to the database: '
Dim connectionString, companyToken
companyToken = Request("companyToken")
If Session(companyToken & " - db") Then
connectionString = "...database=" & Session(companyToken & " - db") & "..."
Else
' Invalid login, go log in again
End If
This assumes that the token will be the same as the company name, for simplicity. So, for instance, somebody will log in for "company1." Having done so successfully, they get a session variable called "company1 - db", which contains the name of the database (in this case, "company1DBName").
Now, every link they follow should have a query string, like "?companyToken=company1" So, when you are connecting to the database, you take that token and use it to find the right database name: Session("company1" + " - db") = "company1DBName"
If they haven't logged in to that company yet (or if they just make up a company name), they won't have that session variable, and they have to go to the log in screen.
If they log in under two companies at once, you can now handle it because you'll be obtaining the database name on every link.
Make sense?
Whatever you do, do not use the user input to create the connection string directly. In other words, the following is the wrong way:
Dim connectionString
connectionString = "...database=" & Request.Form("companyDB") & "..."
Good luck!