This topic is locked

Custom Code not changing actual DB value

6/11/2007 9:40:22 AM
ASPRunnerPro General questions
S
stealthwifi author

Hello,
I have the following code in the Custom Code area on one of the objects in my asprunner project. This code works perfect and changes the value that you see (and color) on the list page, view page, and print and everything. The only problum is it does not actully change in the DB. So if it shows "Open" on the list page it still shows "Closed" in the actual database value. Is there any way for it to change the DB value to match?
[codebox]str = "<span style=""width:100%;BACKGROUND: "

str1 = rs("ClosedDate")

str2 = rs("TargetDate")

if IsNull(str1) = false then

str = str & "Green"

strValue = "Closed"

elseif (now) > str2 then

str = str & "Red"

strValue = "Open"

else

str = str & "Yellow"

strValue = "Open"

end if

str = str &""">"&strValue

strValue = str[/codebox]

B
berkeleyjw 6/11/2007

I don't know what event this code is in, but to do what I think you want it to do, you would have to change the appropriate dictionary item before the record is saved (so it would have to be in BeforeEdit or BeforeAdd). You would have to execute your logic and then have a line something like this:

dict("myfield") = myNewValue

Maybe the others can give you more help.

Sergey Kornilov admin 6/11/2007

Custom code only applies to List/View page. It doesn't change anything in the database.
To change field value in the database use events like BeforeAdd/BeforeEdit.

S
stealthwifi author 6/12/2007

Would the code need to look somthing like this?
[codebox]Function BeforeAdd(dict)
Dim var1, var2
var1 = ClosedDate

var2 = TargetDate
If IsNull(ClosedDate) = false then

dict("OpenClosed") = "Closed"

else if (now) > TargetDate then

dict("OpenClosed") = "Open"

else dict("OpenClosed") = "Open"
end if

end if

[/codebox]
I have been playing around with the code for a few hours now and keep getting diffrent errors, i think it is my syntax or something i will keep trying. Thank you for all your help!
Cheers,

Stealth-

Sergey Kornilov admin 6/12/2007
Function BeforeAdd(dict)
If IsNull(dict("ClosedDate")) = false then

dict("OpenClosed") = "Closed"

else if now() > dict("TargetDate") then

dict("OpenClosed") = "Open"

else

dict("OpenClosed") = "Open"

end if
end function
S
stealthwifi author 6/12/2007

Works absolutly perfect <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=18811&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />
Thanks again you guys really saved me!
Cheers,

Stealth-