This topic is locked

Help with beforeAdd event code

4/15/2007 10:27:26 PM
ASPRunnerPro General questions
F
fnqchick author

Hi Everyone,
I have the code below in the BeforeAdd event. I used it prior to going to version 4.1 and it worked fine. I have since upgraded and now the code doesn't work.
Could one of the advanced users maybe tell me what I am doing wrong?
The RequesterName, RequestorEmail, ApprovedSpend, ManagerName, ManagerEmail, ManagerMaxSpend are all set via dependant dropdown fields.
Thanks heaps,

FNQChick
Function BeforeAdd(dict)
' Parameters:

' dict - Scripting.Dictionary object.

' Each field on the Add form represented as 'Field name'-'Field value' pair
If dict("GSTIncl") = "Yes" then

dict("TotalAmount") = dict("Amount")+ 0

Else

dict("TotalAmount") = dict("Amount")+(dict("Amount")*0.10)

End if
If dict("TotalAmount") < dict("ApprovedSpend") then

dict("ApproverName") = dict("RequestorName")

dict("ApproverEmail")= dict("RequestorEmail")

else

if dict("TotalAmount") > dict("ApprovedSpend") And dict("TotalAmount") < dict("ManagerMaxSpend") then

dict("ApproverName") = dict("ManagerName")

dict("ApproverEmail") = dict("ManagerEmail")

Else

if dict("TotalAmount") > dict("ManagerMaxSpend") then

dict("ApproverName") = "Leadership Team"

dict("ApproverEmail") = "person1@balkanu.com.au" &","& "person2@balkanu.com.au"

End if

End if

End if
BeforeAdd = True
' set BeforeAdd to True if you like to proceed with adding new record

' set it to False in other case
End Function

Sergey Kornilov admin 4/16/2007

The code itself looks good.
I need to see an explanation of "it doesn't work".
Just in case make sure fields that participate in calculation are not NULL.

F
fnqchick author 4/16/2007

The code itself looks good.

I need to see an explanation of "it doesn't work".
Just in case make sure fields that participate in calculation are not NULL.


The ApproverName is always the Requestor, no matter how much the TotalAmount is.
If I adjust the code in any way it is always the Manager or Leadership Team. There is no consistency.
I did a response.write and the total amount, approved spend and manager max spend totals are correct. All totals are based on either a required entry field or a dependant dropdown, they are fully populated in another table.
There is one dependant dropdown field that populates when you add the record but is not there after save - it is blank. This field is a business unit field and has nothing to do with the code, could this be the problem?
Cheers,

FNQChick

F
fnqchick author 4/16/2007

If I replace all dict values with real values it works fine.
It seems to be this line that is being skipped....
if dict("TotalAmount")> dict("ApprovedSpend") And dict("TotalAmount") < dict("ManagerMaxSpend") then
The ApprovedSpend field and the ManagerMaxSpend field are sourced from the same field in tblUsers - would this be an issue?
ie
username

email

spend

manager

manager email
the dropdown box looks up the username and then fills in the other details - a manager is also a username - therefore managermaxspend is the spend for that username.

F
fnqchick author 4/16/2007

Are you sure someone can't help me? I have only about 6 hours left to get this done.

Alexey admin 4/16/2007

Hi,
make sure you have proper values in dict("ApprovedSpend") and dict("ManagerMaxSpend")

Display them on the page using response.writeclause.

F
fnqchick author 4/17/2007

Hi,

make sure you have proper values in dict("ApprovedSpend") and dict("ManagerMaxSpend")

Display them on the page using response.writeclause.


I used response.write and the values are all correct, i even took out the fields and added real numbers and the code worked fine.

C
clig 4/17/2007



I used response.write and the values are all correct, i even took out the fields and added real numbers and the code worked fine.


compare them as INT(dict("ApprovedSpend")) or something

F
fnqchick author 4/21/2007



compare them as INT(dict("ApprovedSpend")) or something


Hi Clig,
I am sorry I haven't replied sooner, I have been interstate.
YOUR SUGGESTION WORKS!!! Thank you so much - you are fantastic..... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=17168&image=1&table=forumreplies' class='bbc_emoticon' alt=':lol:' />