adspmo
asked on
Field not showing the right values
This is driving me nuts
I run a script
I see the values they are the right values
I check the variable in the debugger and they are right
When the script finishes the value in the field is wrong
These are number fields
I think the script is fine ,could be something in the field
If Not doc Is Nothing Then
If note.type(0) = "Sick" Then
tmpNewSickDays = note.SickDaysOff(0)
tmpSickDays = tmpNewSickDays + doc.SickDaysAH(0)
doc.SickDaysAH = tmpSickDays
End If
I run a script
I see the values they are the right values
I check the variable in the debugger and they are right
When the script finishes the value in the field is wrong
These are number fields
I think the script is fine ,could be something in the field
If Not doc Is Nothing Then
If note.type(0) = "Sick" Then
tmpNewSickDays = note.SickDaysOff(0)
tmpSickDays = tmpNewSickDays + doc.SickDaysAH(0)
doc.SickDaysAH = tmpSickDays
End If
ASKER
this is in a Global script
It used to work up untill an hour ago
Sub Approved
'Set the session and db variables
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument, note As notesdocument
Dim view As NotesView
Set note = ws.CurrentDocument.Documen t
Set db = session.CurrentDatabase
Set view = db.GetView( "AvailHol")
If view Is Nothing Then
Msgbox "Cannot find view"
Exit Sub
End If
If note.HasItem("NameFull") Then
Set doc = view.GetDocumentByKey(note .NameFull( 0)) ' KEY Value passed to view
Else
Msgbox "No leave document found for this employee"
End If
If Not doc Is Nothing Then
'The conditions for processing the vacation vary greatly thus the variety of variables
'There is a field named carry over and it may contain Carried over vacation days. These need to be used first
'then the alloted vacation. If the Carry Over are not used by July then they are forfeited
If note.type(0) = "Vacation" And Month(note.StartDate(0)) >6 Then '
tmpNewDaysTotal = note.NewDaysTotal(0) 'Number of actual vacation days
tmpAllowanceAH_1 = tmpNewDaysTotal + doc.AllowanceAH_1(0) 'calculate the number of used vacation days
tmpAllowanceAH_2 = doc.allowanceAH_2(0) - tmpNewDaysTotal ' calculate the remaining vacation days
doc.AllowanceAH_1 = tmpAllowanceAH_1
doc.AllowanceAH_2 = tmpAllowanceAH_2
doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0) 'Calculate the used vacation days
doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)'Calcu late the remaining vacation days
Goto SaveIt
Else
If Month(note.StartDate(0)) < 6 And note.type(0) = "Vacation" Then
If note.newdaystotal(0) =< doc.CarriedOverAH_2(0) Then 'Check the carryover remaing days first
doc.CarriedOverAH_1 = doc.CarriedOverAH_1(0) + note.NewDaysTotal(0) 'Calculate the used carryover days
doc.CarriedOverAH_2 = doc.CarriedOverAH(0) - note.NewDaysTotal(0) 'Calculate the remaining carryover days days
doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)'Calcu late the used vacation days
doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)'Calcu late the remaining vacation days
Goto SaveIt
Else
If (doc.CarriedOverAH_2(0) <> 0) And (note.newdaystotal(0) > doc.CarriedOverAH_2(0)) Then
tmpCarriedOverAH_2 = doc.CarriedOverAH_2(0) 'Get the current value
tmpNewDay = note.newdaystotal(0) - tmpCarriedOverAH_2 'Calculate the difference between the requested and the carryover
tmpAllowanceAH_2 = doc.AllowanceAH_2(0) - tmpNewDay ' calculate the remaining vacation days
tmpAllowanceAH_1 = doc.AllowanceAH_1(0) + tmpNewDay 'calculate the number of used vacation days
doc.CarriedOverAH_1 = doc.CarriedOverAH_1(0) + tmpCarriedOverAH_2 'Calculate the used carryover days
doc.CarriedOverAH_2 = 0 'Set the available to 0
doc.AllowanceAH_1 = tmpAllowanceAH_1 'Set the values
doc.AllowanceAH_2 = tmpAllowanceAH_2 'Set the values
doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0) 'Calculate the used vacation days
doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0) 'Calculate the remaining vacation days
Goto SaveIt
Else
If doc.CarriedOverAH_2(0) = 0 Then
tmpNewDaysTotal = note.NewDaysTotal(0) 'Requested days vacation
tmpAllowanceAH_1 = tmpNewDaysTotal + doc.AllowanceAH_1(0) 'calculate the number of used vacation days
tmpAllowanceAH_2 = doc.allowanceAH_2(0) - tmpNewDaysTotal ' calculate the remaining vacation days
doc.AllowanceAH_1 = tmpAllowanceAH_1 'Set the values
doc.AllowanceAH_2 = tmpAllowanceAH_2 'Set the values
doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0) 'Calculate the used vacation days
doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0) 'Calculate the remaining vacation days
Goto SaveIt
End If
End If
End If
End If
End If
If note.type(0) = "Personal" Then
tmpPersonalDaysAH_2 =doc.PersonalDaysAH_2(0) - note.NewDaysTotal(0) 'Calculate the remaining personaldays
tmpPersonalDaysAH_1 = note.NewDaysTotal(0) + doc.PersonalDaysAH_1(0)'Ca lculate the used days
doc.PersonalDaysAH_2 = tmpPersonalDaysAH_2 'Set the values
doc.PersonalDaysAH_1 = tmpPersonalDaysAH_1 'Set the values
Goto SaveIt
If note.type(0) = "Work From Home" Then
End If
SaveIT:
doc.ComputeWithForm True, False
doc.save True, False
End If
End If
End Sub
It used to work up untill an hour ago
Sub Approved
'Set the session and db variables
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument, note As notesdocument
Dim view As NotesView
Set note = ws.CurrentDocument.Documen
Set db = session.CurrentDatabase
Set view = db.GetView( "AvailHol")
If view Is Nothing Then
Msgbox "Cannot find view"
Exit Sub
End If
If note.HasItem("NameFull") Then
Set doc = view.GetDocumentByKey(note
Else
Msgbox "No leave document found for this employee"
End If
If Not doc Is Nothing Then
'The conditions for processing the vacation vary greatly thus the variety of variables
'There is a field named carry over and it may contain Carried over vacation days. These need to be used first
'then the alloted vacation. If the Carry Over are not used by July then they are forfeited
If note.type(0) = "Vacation" And Month(note.StartDate(0)) >6 Then '
tmpNewDaysTotal = note.NewDaysTotal(0) 'Number of actual vacation days
tmpAllowanceAH_1 = tmpNewDaysTotal + doc.AllowanceAH_1(0) 'calculate the number of used vacation days
tmpAllowanceAH_2 = doc.allowanceAH_2(0) - tmpNewDaysTotal ' calculate the remaining vacation days
doc.AllowanceAH_1 = tmpAllowanceAH_1
doc.AllowanceAH_2 = tmpAllowanceAH_2
doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0) 'Calculate the used vacation days
doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)'Calcu
Goto SaveIt
Else
If Month(note.StartDate(0)) < 6 And note.type(0) = "Vacation" Then
If note.newdaystotal(0) =< doc.CarriedOverAH_2(0) Then 'Check the carryover remaing days first
doc.CarriedOverAH_1 = doc.CarriedOverAH_1(0) + note.NewDaysTotal(0) 'Calculate the used carryover days
doc.CarriedOverAH_2 = doc.CarriedOverAH(0) - note.NewDaysTotal(0) 'Calculate the remaining carryover days days
doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0)'Calcu
doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0)'Calcu
Goto SaveIt
Else
If (doc.CarriedOverAH_2(0) <> 0) And (note.newdaystotal(0) > doc.CarriedOverAH_2(0)) Then
tmpCarriedOverAH_2 = doc.CarriedOverAH_2(0) 'Get the current value
tmpNewDay = note.newdaystotal(0) - tmpCarriedOverAH_2 'Calculate the difference between the requested and the carryover
tmpAllowanceAH_2 = doc.AllowanceAH_2(0) - tmpNewDay ' calculate the remaining vacation days
tmpAllowanceAH_1 = doc.AllowanceAH_1(0) + tmpNewDay 'calculate the number of used vacation days
doc.CarriedOverAH_1 = doc.CarriedOverAH_1(0) + tmpCarriedOverAH_2 'Calculate the used carryover days
doc.CarriedOverAH_2 = 0 'Set the available to 0
doc.AllowanceAH_1 = tmpAllowanceAH_1 'Set the values
doc.AllowanceAH_2 = tmpAllowanceAH_2 'Set the values
doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0) 'Calculate the used vacation days
doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0) 'Calculate the remaining vacation days
Goto SaveIt
Else
If doc.CarriedOverAH_2(0) = 0 Then
tmpNewDaysTotal = note.NewDaysTotal(0) 'Requested days vacation
tmpAllowanceAH_1 = tmpNewDaysTotal + doc.AllowanceAH_1(0) 'calculate the number of used vacation days
tmpAllowanceAH_2 = doc.allowanceAH_2(0) - tmpNewDaysTotal ' calculate the remaining vacation days
doc.AllowanceAH_1 = tmpAllowanceAH_1 'Set the values
doc.AllowanceAH_2 = tmpAllowanceAH_2 'Set the values
doc.totalAH_1 = doc.CarriedOverAH_1(0) + doc.AllowanceAH_1(0) 'Calculate the used vacation days
doc.totalAH_2 = doc.CarriedOverAH_2(0) + doc.AllowanceAH_2(0) 'Calculate the remaining vacation days
Goto SaveIt
End If
End If
End If
End If
End If
If note.type(0) = "Personal" Then
tmpPersonalDaysAH_2 =doc.PersonalDaysAH_2(0) - note.NewDaysTotal(0) 'Calculate the remaining personaldays
tmpPersonalDaysAH_1 = note.NewDaysTotal(0) + doc.PersonalDaysAH_1(0)'Ca
doc.PersonalDaysAH_2 = tmpPersonalDaysAH_2 'Set the values
doc.PersonalDaysAH_1 = tmpPersonalDaysAH_1 'Set the values
Goto SaveIt
If note.type(0) = "Work From Home" Then
End If
SaveIT:
doc.ComputeWithForm True, False
doc.save True, False
End If
End If
End Sub
By GLOBAL SCRIPT, do you mean code in the GLOBALS section of a form?
The script is much too long, therefore the algorithm is too complex. I'd like to suggest a different approach, which simplifies your calculations considerably. If I may...
You calculate vacation days differently before and after the 1st of July. These calculations are not necessary, if you do the following:
- you create an agent running on July 1st (either manually or automatically)
- this agent adds an additional vacation document if required (!)
- the vacation document will be filled with the vacation days carried over but unused
Of course, you should be able to identify that the additional vacation document is not a real vacation, so you'd probably have to set the type of the document to a certain value. This also makes it easy to hide this type in the vacation views shown to your users.
Hope this might help, although I'm maybe a little late...
Sjef
You calculate vacation days differently before and after the 1st of July. These calculations are not necessary, if you do the following:
- you create an agent running on July 1st (either manually or automatically)
- this agent adds an additional vacation document if required (!)
- the vacation document will be filled with the vacation days carried over but unused
Of course, you should be able to identify that the additional vacation document is not a real vacation, so you'd probably have to set the type of the document to a certain value. This also makes it easy to hide this type in the vacation views shown to your users.
Hope this might help, although I'm maybe a little late...
Sjef
ASKER
Yes I mean the Globals section
This works it is just not returning half days
It used to , I have touched nothing
The values in the Variables screen show correctly. e.g 1.5 When the script finishes it shows as 2 Should I be using some IntegerScript or something
James
This works it is just not returning half days
It used to , I have touched nothing
The values in the Variables screen show correctly. e.g 1.5 When the script finishes it shows as 2 Should I be using some IntegerScript or something
James
Check the data type and input translation of the field to see if it has some functions that might round of the values
~Hemanth
~Hemanth
ASKER
It is a Number Field Computed. I had already looked for that info
James
James
ASKER
I think I got it the QuerySave is running twice
When I press the Submit button it runs and sets the right value in this case .5
It then runs again and .5 = .5 =1
How do I stop the query from running twice, Use a flag?
When I press the Submit button it runs and sets the right value in this case .5
It then runs again and .5 = .5 =1
How do I stop the query from running twice, Use a flag?
Do you have Header in the form ? If so remove it.. this causes querysave to run twice
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is this script within a form, an agent, or a view action button?
Form? Try:
Dim ws as new notesUiWorkspace
ws.currentDocument.Reload
Agent or view action? You probably need doc.save true,false