We help IT Professionals succeed at work.

How to add append a value to a field in the form with lotusscript

fatihdi
fatihdi asked
on
2,436 Views
Last Modified: 2013-12-18
Hi,

I am a newbie to lotus and lotusscript as a matter of fact. What I need is we have domino workflow tool in my company and the domino server,we have workflows in the system.

The management asks us to enable some people to see some of the forms, so I have opened the Workflow Architect of Domino workflow and added the corresponding persons to the Readers field and activated it but this of course will only work in newly created forms. For the previously created forms I want to write a lotusscript agent that will update the ProcessReaderExpandedOS field so that those persons can see the form. I have written the following form in the initialize part of lotusscript agent.I get an error of Data not saved due to script error(s).

 script error what should i do?
Comment
Watch Question

Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
The first red line indicates that you intend to compare a NotesItem to a String, which isn't possible. The values of the item are in the Values(array), so a better comparison would be

      If item.Values(0)="Seyahat" Then

The second red line I don't understand, what do you want? item2 is already updated.

Next, what you forgot maybe: to save the document! Just before the line with GetNextDocument, add a line with
      Call doc.Save(True, False)

Finally, a warning: it could be that the type of the Readers field changes to Text instead of Names. You might have to add one more line, just before the Save()
      item2.IsReaders= True

Hope it works better after these modifications.

Author

Commented:
I am trying to change the field of ProcessReaderExpandedOS in the form to item2 actually...i have the desired value which is item2,want to make the value of ProcessReaderExpandedOS ,item2...how can i assign it?
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
The item exists in the document I hope. So what is done is correct:
- you get item2
- you add some people
- you should not assign, for the names are already added to the item
- now you have to save the document

What is your current code, just in text?

Author

Commented:
Dim  db As New NotesDatabase("COROLLA\TOYOTASA","Workflow\TSAAppl.nsf")

Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim item As NotesItem
Dim item2 As NotesItem
Dim subject As String
      
Set dc = db.AllDocuments
Set doc = dc.GetFirstDocument()
      
While Not(doc Is Nothing)
            
If item="Seyahat" Then
            
Set item2=doc.GetFirstItem("ProcessReaderExpandedOS")
item2.AppendToTextList("CN=Nurgul GULER/O=TOYOTA")
item2.AppendToTextList("CN=Lutfi OZDEMIR/O=TOYOTA")
item2.AppendToTextList("CN=Tugba CORTELEKOGLU/O=TOYOTA")
Set doc.GetFirstItem("ProcessReaderExpandedOS")=item2

End if

Set doc = dc.GetNextDocument(doc)
WEND


Above is the code

Above i only try to update the ProcessExpandedReaderOS field.this field has some value but i need to add some other value to this item what could i be doing wrong?

Author

Commented:
The problem is I fill item2 field but it is filled from ProcessReaderExpandedOS field so I need to fill this field with values added item2.I need to assign the value of item to ProcessReaderExpandedOS field for every document in the database which has item="Seyahat" and item is filled from the ProcessOS field

thank you
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
But that's the unchanged code!! Didn't you apply my earlier comments?

Maybe I don't understand you, or you don't understand me, but (once again) I'll try to explain: item2 is the field ProcessReaderExpandedOS, when you change the item the value in the document changes. If you want the values to remain changed when the agent end, you have to SAVE the document.

Proposed code below:
Dim  db As New NotesDatabase("COROLLA\TOYOTASA","Workflow\TSAAppl.nsf")

Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim item As NotesItem
Dim item2 As NotesItem
Dim subject As String
      
Set dc = db.AllDocuments
Set doc = dc.GetFirstDocument()
      
Do Until doc Is Nothing
            
	If Instr(item.Values(0), "Seyahat")>0 Then
            
		Set item2= doc.GetFirstItem("ProcessReaderExpandedOS")	
		item2.AppendToTextList("CN=Nurgul GULER/O=TOYOTA")
		item2.AppendToTextList("CN=Lutfi OZDEMIR/O=TOYOTA")
		item2.AppendToTextList("CN=Tugba CORTELEKOGLU/O=TOYOTA")
		item2.IsReaders= True
		Call doc.Save(True, False)
	
	End if

	Set doc = dc.GetNextDocument(doc)
Loop

Open in new window

Author

Commented:
Hi, Now I totally understand you. You tell me that if I change item2 ,ProcessReaderExpandedOS automatically change without the need to assign item2 to ProcessReaderExpandedOS.

I tried to save the agent and it did not give me any errors but after save when i tried to run it it gave the error in the screenshot...why would that happen it could not open the database....



screenshoterror.jpg
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
First advice: run this first on a test database! Make a copy, and test it on that database.

Here you try to open the database Workflow/TSAAppl.nsf on server COROLLA/TOYOTASA. There are several reason why you would get that error:
- it is a new replica and it is empty
- you have insufficient rights (although I'd expect a different message)
- and the most important one: you need to open it explicitly

Replace line 1 by
      Dim db As New NotesDatabase ("", "")
      Call db.Open("COROLLA\TOYOTASA","Workflow\TSAAppl.nsf")

But if the database is actually the current database, you don't have to open it: it is open. Just use
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Set db= session.CurrentDatabase

Author

Commented:
Hi,

it seems like it is working but then I get another different error,saying that object variable not set.

For
1-The database is not empty all the workflow forms are here
2- I have all the rights,I am the manager with delete create agents,private agents everything...
3-I tried opening the database explicitly I get the following error. why is that? object variable not set


error.jpg

Author

Commented:
I have written all the code to the initialize part of the agent would that be a problem?
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
There's one line missing in the code:
      Set item= doc.GetFirstItem("PROCESSOS")

Consequently, item is still an object variable with nothing assigned to it.

Author

Commented:
Below is the code i have also included the line you mentioned, i get the object variable not set error in this code snippet.
Dim session As New NotesSession
	Dim db As NotesDatabase
	Set db= session.CurrentDatabase 
	Dim dc As NotesDocumentCollection
	Dim doc As NotesDocument
	Dim item As NotesItem
	Dim item2 As NotesItem
	Dim subject As String
	
	Set dc = db.AllDocuments
	Set doc = dc.GetFirstDocument()
	Set item= doc.GetFirstItem("PROCESSOS")
	
	Do Until doc Is Nothing
		
		If Instr(item.Values(0), "Copy_Fatih_Seyehat")>0 Then
			
			Set item2= doc.GetFirstItem("ProcessReaderExpandedOS")	
			item2.AppendToTextList("CN=Nurgul GULER/O=TOYOTA")
			item2.AppendToTextList("CN=Lutfi OZDEMIR/O=TOYOTA")
			item2.AppendToTextList("CN=Tugba CORTELEKOGLU/O=TOYOTA")
			item2.IsReaders= True
			Call doc.Save(True, False)
			
		End If
		
		Set doc = dc.GetNextDocument(doc)
	Loop

Open in new window

Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
item changes with every doc, so it has to be inside the loop

Move line 12 after line 14

Author

Commented:
If I use

 Dim db As New NotesDatabase ("", "")
      Call db.Open("COROLLA\TOYOTASA","Workflow\TSAAppl.nsf")


Then I get the error:

 Database COROLLA\TOYOTASA!! Workflow\TSAAppl.nsf has not been opened yet

Author

Commented:
I moved it inside the loop and it is still the same, now I assign item inside the loop but nothing has changed. although it was not inside the loop it should have been worked for 1 document and for test purpose I was aiming to modify 1 document and i checked the document , agent did not modify it somehow. what should i do?
Groupware Consultant
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Sorry for late reponse...tnx for help
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.