01. juli 2004 - 09:10Der er
6 kommentarer og 1 løsning
Sætte værdier på andre dokumenter, fundet udfra felter
Hej,
Jeg er ny ud i LS forunderlige verden....
jeg har et dokument, hvor jeg har 50 felter*2 ProductID_1 - ProductID_50 og amount_1 - amount 50
Nu vil jeg så lave en agent trigget af en knap, der løber productid_ felterne igennem, Når den finder en værdi, skal den slå op i et view vPRODUCTSKEY efter værdien fra feltet. Her skal den så opdaterer et felt CurrentAmount med værdien fra Amount_ felterne....
Nu griner i sikket af min kode, men PLEASE hjælp...
Jeg er gået i stå ved at jeg ikke kan få fat i en værdi på det document jeg henter med getdocumentbykey
Sub Initialize Dim session As New notessession Dim workspace As New NotesUIWorkspace Dim uidoc As NotesUIDocument Dim doc As NotesDocument Dim products() As String Dim db1 As notesdatabase Dim view As notesview Dim counter As Integer
Set db1= session.currentdatabase Set view = db1.getview("vPRODUCTSKEY") Set uidoc = workspace.currentDocument
For counter%=1 To 50 tmp = "productid_"+Cstr(counter%) tmp2 = uidoc.Fieldgettext(tmp) If tmp2 <> "0" & tmp2 <> "" Then Set doc = view.GetDocumentBykey(tmp2) Print tmp2 tmp3 = doc.GetItemValue( "ProductName" ) Print tmp3
Teknologi, AI og forretning er i centrum på Computerworlds Cloud og AI Festival i København d. 18. og 19. september. Se hele programmet for den store konference om strategisk brug af Cloud og AI på: www.cloud-festival.dk
Nu er jeg kommet et skridt videre og min kode ser nu således ud, og så får jeg en type mismatch...
Sub Initialize Dim session As New notessession Dim workspace As New NotesUIWorkspace Dim uidoc As NotesUIDocument Dim doc As NotesDocument Dim products() As String Dim db1 As notesdatabase Dim view As notesview Dim counter As Integer Dim tmp As String,tmp2 As String,tmp3 As Double Set db1= session.currentdatabase Set view = db1.getview("vPRODUCTSKEY") Set uidoc = workspace.currentDocument
For counter%=1 To 50 tmp = "productid_"+Cstr(counter%) tmp2 = uidoc.Fieldgettext(tmp) If tmp2 <> "0" And tmp2 <> "" Then Set doc = view.GetDocumentBykey(tmp2) If Not doc Is Nothing Then tmp3 = doc.GetItemValue( "MinimumAmount" ) Call uidoc.FieldSetText("ActualAmount",tmp3) End If End If Next End Sub
Både minimumamount og actualamount er nummerfelter
Cool har fået det til at virke, dog på en lidt anden måde, nemlig :
Sub Initialize Dim session As New notessession Dim workspace As New NotesUIWorkspace Dim uidoc As NotesUIDocument Dim doc As NotesDocument Dim products() As String Dim db1 As notesdatabase Dim view As notesview Dim counter As Integer Dim tmp As String,tmp2 As String,orgval As Double, tmp4 As String,amount As Double,newval As Double Set db1= session.currentdatabase Set view = db1.getview("vPRODUCTSKEY") Set uidoc = workspace.currentDocument Dim item As NotesItem
For counter%=1 To 50 tmp = "productid_"+Cstr(counter%) tmp4 = "amount_"+Cstr(counter%) tmp2 = uidoc.Fieldgettext(tmp) If tmp2 <> "0" And tmp2 <> "" Then Set doc = view.GetDocumentBykey(tmp2) If Not doc Is Nothing Then orgval = Cint(doc.actualAmount(0)) amount = uidoc.fieldgettext(tmp4)
newval= orgval - amount Print uidoc.Fieldgettext("product_"+Cstr(counter%) ) & " antal : " & amount &" original : " & doc.ActualAmount(0) &" ny :" newval doc.editmode = True Call doc.ReplaceItemValue("ActualAmount", Cstr(newval)) Print doc.ActualAmount(0) Call doc.save(False,False) End If End If Next End Sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.