From my code below try to Looping from "GetAllDocumentbyKey" and Set Unique number each document for to show in Folder View , but from my code it's not work.
How should I solve this problem?
Dim defect As Variant
defect = uidoc.FieldGetText("DefectMode")
keys( 0 ) =defect
Dim PartNo As Variant
partNo = uidoc.FieldGetText("PartNo")
keys( 1 ) = partNo
Set view = db.GetView("EmbedView2" )
Set dc = view.GetAllDocumentsByKey(keys,False)
Call dc.PutAllInFolder("EmbedFolder")
Do Until dc Is Nothing
call uidoc.FieldSetText("UniqueNo","number") // this code I try to set unique number to each document by number that's I plan to increase 1 , I have to set in "UniqueNo" Fieled
Loop
OK... There is a big part missing from your code.
uidoc is the currently open document and if I guess right, it has an embedded view in it called "EmbedFolder". The documents you want to modify all belong to a special DefectMode and a special PartNo (that of the currently open document)
I doubt that what you want makes sense, but I don't wanna go into that.
To make your code work you need to cycle through the document collection and set each documents value separately. This would simply look like this:
Dim intNumber as Integer
Dim doc as NotesDocument
intNumber = 1
Set doc = dc.GetFirstDocument()
Do until doc is Nothing
Call doc.ReplaceItemValue( "UniqueNo" , intNumber )
Call doc.Save( True, True, True )
Set doc = dc.GetNextDocument( doc )
Wend
Related
I use an Excel macro to get values from SAP, especially for planned orders.
Function GetOrders(ByVal ProductNumber As String)
Dim OrderList As Object: Set OrderList = SAP.Add("BAPI_MATERIAL_MRP_LIST")
Dim OrderMat As Object: Set OrderMat = OrderList.Exports("MATERIAL")
Dim OrderPlant As Object: Set OrderPlant = OrderList.Exports("PLANT")
Dim OrderTable As Object: Set OrderTable = OrderList.Tables("MRP_IND_LINES")
OrderTable.FreeTable
OrderMat = ProductNumber
OrderPlant = "XXX"
OrderList.Call
Set GetOrders = OrderTable
Set OrderMat = Nothing
Set OrderPlant = Nothing
Set OrderTable = Nothing
End Function
I changed the OrderPlant for the question.
It's working on one PC but using the same SAP account on another one we get some empty values. Specifically all the numbers > 10k are not shown.
On my PC I get something like this as a result from the MRP_IND_LINES table:
P.cons 00XXXXXXXX/XXXXXX/XXXX -21.600.000
P.cons 00XXXXXXXX/XXXXXX/XXXX -3.600.000
On another PC I the -21.600.000 is empty so it shows like this:
P.cons 00XXXXXXXX/XXXXXX/XXXX
P.cons 00XXXXXXXX/XXXXXX/XXXX -3.600.000
The disappearing field is the "REC_REQD_QTY", number 16 of the table BAPI_MRP_IND_LINES (MRP: Single Lines of MRP Elements), Data Type: "QUAN"
The only difference between the PCs is the SAP logon GUI version, 720 on mine and 750 on the other PC.
This happens only on the big numbers. The other fields in the row are downloaded correctly.
I'm not using SAP GUI scripting, but I've created the SAP Object with the row
Set SAP = CreateObject("SAP.Functions.Unicode")
In a LotusScript driven application we make heavy use of NotesDirectory.LookupNames to create DirNavs and retrieve data from person documents. Works fine just using the server's primary NAB: we're using ($Users) view for the lookup then return values from the matching person documents' fields.
Now we have to extend this so that we also are able to lookup people stored in a secondary NAB. This secondary NAB is replicated to the server where the application is running, and Directory Assistance is set up. AFAIK DA is basically working (e.g. the secondary NAB can be selected from in standard names dialogs), and the secondary NAB appears to be a full directory; at least database properties say that it's a "Domino Directory" type of DB.
Problem is: using NotesDirectory.LookupNames does not yield any results if we're looking for names stored in the secondary NAB, while looking for names stored in the primary one still works
Server this runs on is V 11.0.1; all NABs and da.nsf are running more or the latest design (ran design refreshes from templates located on a V 10.0.1 server)
Main question is: is this supposed to work in the first place?
Documentation for the class just speaks of "the directories", so I assume that this should be possible.
Any hint is very welcome
-- UPDATE 2021-02-24 --
for completeness here's the (corrected) test agent's code as suggested by Scott: user #1 is from the primary directory while #2 is from the secondary one
Sub Initialize
Dim sn As New NotesSession
Dim nDir As NotesDirectory
Dim nDirNav As NotesDirectoryNavigator
Dim sKey As String, sVw As String, sSrv As String
Dim vItems As Variant, vItem As Variant, vResult As Variant, vKeys As Variant
Dim i As Integer
sVw = "($Users)"
sSrv = "devtest/edcomTest"
Set nDir = sn.Getdirectory(sSrv)
nDir.Searchalldirectories = True 'Not really necessary, but doesn't hurt either
ReDim vKeys(1)
vKeys(0) = "sautor1"
vKeys(1) = "Veronika.Test#edcomtest.de"
ReDim vItems(2)
vItems(0) = "Type"
vItems(1) = "FullName"
vItems(2) = "ShortName"
ReDim vResult(0)
Set nDirNav = nDir.Lookupnames(sVw, vKeys, vItems, False)
Do While nDirNav.Namelocated
Do While nDirNav.Matchlocated
vItem = nDirNav.Getfirstitemvalue()
vResult(0) = vItem(0)
'Looping the other items
For i=1 To 2
vItem = nDirNav.Getnextitemvalue()
vResult = ArrayAppend(vResult, vItem(0))
Next
Call nDirNav.Findnextmatch()
Loop
Call nDirNav.Findnextname()
Loop
Print Join(vResult, "; ")
End Sub
I'm highly embarrassed as the cause for this "failure" was a simple typo in a user's name, where I simply had mispelled "Veronika" as "Veronica"...
(It's already corrected in the code snippet above)
i am trying to write a code to open VBA and do search based on the cell value in A1 (integer). i managed to write a code up to point where i can open the lotus notes and go to specific database. I tried many online codes but couldn't manage to find the code to search in that database. "Lotus.NotesSession" doesn't work the excel version i use. Could you please help me to finish this code. Code is below:
Sub macro4()
Dim uiWs As Object
Dim dbname As String
Dim serverName As String
Dim db As NotesDatabase
Dim doccol As NotesDocumentCollection
Dim varA As Integer
dbname = "***"
serverName = "***"
Set uiWs = CreateObject("Notes.NotesUIWorkSpace")
Call uiWs.OpenDatabase(serverName, dbname)
Set db = uiWs.GetDatabase(serverName, dbname) ---->where i get the error
varA.Value = Sheets("sheet1").Range("A1").Value
Set doccol = db.FTSearch(varA, Nothing, 0)
End Sub
In Notes there are two "parent"- classes to derive everything from. The NotesUIWorkspace is the class for the "frontend": It contains everything that you SEE in the client. The NotesSession is the class for the backend. NotesDatabase is a backend- class. To correctly get your database, you need to use NotesSession:
Set ses = CreateObject("Notes.NotesSession")
Set db = ses.GetDatabase(serverName, dbname)
You mixed up COM and OLE Integration. The thing you tried to use (Lotus.NotesSession) is for COM only and you need to include Notes in your project to use this.
For your example to work you need to use the OLE integration: Notes.NotesSession
Now to your "Search"- Code:
There are two different ways to search a NotesDatabase:
There is the Fulltextsearch and the "normal" search.
The Fulltextsearch just searches for your value everywhere in all documents and returns a collection. A search for "Tom" in a mailfile will find all mails / calendar entries that where:
sent by Tom
received by Tom
have the word "Tom" in subject or body or an attachment of the mail.
The syntax for FTSearch is:
Set doccol = db.FTSearch( YourSearchValue )
You can restrict the search to one certain field by using a special syntax for your search. e.G. to only search in the "From" field you could write
[From] = "YourSearchValue"
In FTSearch the "=" always means "contains"
The normal search uses a Formula (in #Formula- syntax) to search for a document. It needs the right syntax, otherwise it will not find anything. A formula to search all documents that come from "Tom" would be:
#Contains( From ; "Tom" )
The syntax for search is:
Set doccol = db.Search( YourQueryAsExampleAbove, Nothing, 0 )
With Nothing = Cutoffdate (if given only return documents created or modified after the date) and 0 = max. number of documents to return (0 = return everything).
So your example code for the could be something like:
strQuery = "FieldToSearch = " & Sheets("sheet1").Range("A1").Value
Set doccol = db.Search( strQuery, Nothing, 0 )
After calling OpenDatabase successfully, you can use
set uiDb = uiWS.CurrentDatabase
That will get a NotesUIDatabase object, and then you can use
set db= uiDb.Database
That will get you the NotesDatabase object that you need in order to call the FTSearch method.
My requirement is, I am having a hundreds of views. I want to make them as standard colors and UI. Simple I am using for changing the font color for column header and column values by NotesViewColumn class. But I do not know that which class is having the property for action bar and View alternate color and Heaer style and etc.,
In javascript is also welcome., But it should change its property as a designer level.
Thanks in advance
You have 3 options:
The easiest one: Go and buy ezView from Ytria. Should take you less than an hour to sort your views out
Create one view that looks the way you want your views to look and then go through all the views in a script, rename them, create a new view based on your view template and copy the view columns from the old views and adjust the view selection formulas (all in LotusScript)
Export your views in DXL and run some XSLT or search/replace to adjust the properties
Hope that helps
I just ran this agent, to change all the views in my (small) test database to having alternate row colours, and it worked.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim exporter As NotesDXLExporter
Dim importer As NotesDXLImporter
Dim out As String
Dim infile As string
Dim pointer As long
Dim filenum As Integer
Dim altrow As integer
Dim unid As String
Dim doc As notesdocument
Set db = session.currentdatabase
Set exporter = session.Createdxlexporter
Set importer = session.Createdxlimporter
Dim count As Integer
count = 1
ForAll v In db.views
unid = v.UniversalID
Set doc = db.getdocumentbyunid(unid)
out = exporter.Export(doc)
altrow = instr(out, "altrowcolor")
If altrow > 0 Then
pointer = InStr(altrow, out, "=")
out = Left(out,pointer) & "'#f7f7f7'" & Mid(out, pointer+10)
else
pointer = InStr(out, "bgcolor=")
pointer = InStr(pointer, out, " ")
out = Left(out,pointer) & "altrowcolor='#f7f7f7' " & Mid(out, pointer+1)
End if
Call importer.setinput(out)
Call importer.setoutput(db)
importer.Designimportoption = 5
importer.Documentimportoption = 5
Call importer.Process()
out = ""
infile = ""
count = count + 1
End ForAll
Print count & " views processed"
End Sub
If your view designs are much bigger, you might want to use a NotesStream instead of String for "out". In that case, from the Help Files, I believe that the stream has to be closed and re-opened before you can use it for import.
For further research, I suggest writing "out" to a file, and examining the xml to find other "hidden" parameters.
Have fun, Phil
I can also recommend ezView. Makes it a piece of cake to modify views. I also use actionBarEZ to modify action bars across applications.
I blogged about a few different development tools I use in Domino Designer, you can find the entry here: http://www.bleedyellow.com/blogs/texasswede/entry/mydevelopmenttools
I am setting up a Lotus Notes account to accept emails from a client, and automatically save each email as a plain text file to be processed by another application.
So, I'm trying to create my very first Agent in Lotus to automatically export the emails to text.
Is there a standard, best practices way to do this?
I've created a LotusScript Agent that pretty much works. However, there is a bug - once the Body of the memo exceeds 32K characters, it starts inserting extra CR/LF pairs.
I am using Lotus Notes 7.0.3.
Here is my script:
Sub Initialize
On Error Goto ErrorCleanup
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim uniqueID As Variant
Dim curView As NotesView
Dim docCount As Integer
Dim notesInputFolder As String
Dim notesValidOutputFolder As String
Dim notesErrorOutputFolder As String
Dim outputFolder As String
Dim fileNum As Integer
Dim bodyRichText As NotesRichTextItem
Dim bodyUnformattedText As String
Dim subjectText As NotesItem
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'INPUT OUTPUT LOCATIONS
outputFolder = "\\PASCRIA\CignaDFS\CUser1\Home\mikebec\MyDocuments\"
notesInputFolder = "IBEmails"
notesValidOutputFolder = "IBEmailsDone"
notesErrorOutputFolder="IBEmailsError"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set db = session.CurrentDatabase
Set curview = db.GetView(notesInputFolder )
docCount = curview.EntryCount
Print "NUMBER OF DOCS " & docCount
fileNum = 1
While (docCount > 0)
'set current doc to
Set doc = curview.GetNthDocument(docCount)
Set bodyRichText = doc.GetFirstItem( "Body" )
bodyUnformattedText = bodyRichText.GetUnformattedText()
Set subjectText = doc.GetFirstItem("Subject")
If subjectText.Text = "LotusAgentTest" Then
uniqueID = Evaluate("#Unique")
Open "\\PASCRIA\CignaDFS\CUser1\Home\mikebec\MyDocuments\email_" & uniqueID(0) & ".txt" For Output As fileNum
Print #fileNum, "Subject:" & subjectText.Text
Print #fileNum, "Date:" & Now
Print #fileNum, bodyUnformattedText
Close fileNum
fileNum = fileNum + 1
Call doc.PutInFolder(notesValidOutputFolder)
Call doc.RemoveFromFolder(notesInputFolder)
End If
doccount = doccount-1
Wend
Exit Sub
ErrorCleanup:
Call sendErrorEmail(db,doc.GetItemValue("From")(0))
Call doc.PutInFolder(notesErrorOutputFolder)
Call doc.RemoveFromFolder(notesInputFolder)
End Sub
Update
Apparently the 32KB issue isn't consistent - so far, it's just one document that starts getting extra carriage returns after 32K.
With regards the 32Kb thing, instead of this:
Set bodyRichText = doc.GetFirstItem( "Body" )
... you might want to consider iterating all "Body" fields in the email document. When dealing with large amounts of rich text, Domino "chunks" said content into multiple rich text fields. Check some documents you're processing: you may well see multiple instances of the "Body" field when you look at document properties.
I'm not sure what is causing the 32K bug, but I know there are lots of limitations in the order of 32K or 64K within Lotus Notes, so perhaps you're running into one of those. I can't imagine what would add extra CR/LFs. Perhaps you could try using the GetFormattedText method on the NotesRichTextItem class and see if it fares better?
It's more complicated, but you might also be able to use the NotesRichTextNavigator class to iterate through all the paragraphs in the memo, outputting them one at a time. Breaking up the output that way might eliminate the CR/LF problem.
Lastly I always suggest Midas' LSX for dealing with rich text in Lotus Notes. They sell an add-on that gives you much more control over rich text fields.
As for best practices, one that comes to mind when I read your code is the looping construct. It is more efficient to get the first document in a view, process it, and then get the next doc and check whether it is equal to Nothing. That sets the loop to run through the view in index order, and eliminates the need to search through the index to find the Nth document each time. It also saves you from maintaining a counter. The gist is as follows:
Set doc = curview.GetFirstDocument()
While Not (doc Is Nothing)
'Do processing here...
Set doc = curview.GetNextDocument(doc)
Wend
The external eMail most likely comes in as MIME. So you could check the document.hasMime and then use the mime classes to get to the content. Then you don't have a 64k limit. Samples are in the help - or reply if you want code.