{{tag>category:"OpenInsight 64-bit" author:"rdhull50" author:"bob carten" author:"Andrew McAuley"}}
[[https://www.revelation.com/the-works|Join The Works program to have access to the most current content, and to be able to ask questions and get answers from Revelation staff and the Revelation community]]
==== Setting the DefValue for a column in a Form (OpenInsight 64-bit) ====
=== At 29 APR 2020 10:16:53PM rdhull50 wrote: ===
Rober Hull
First of all, I am new to OI. I have spent a lot of time in AREV, so I am trying to learn how to do things in an OI Form that I used to do in an AREV Window.
An Example:
I have a Form named "[b]WIN_VISITS[/b]". It is populated as follows:
Visit # [b](EDL_ID[/b]) this is initially set by the SeqKey
User ID ([b]EDL_User_ID[/b])
Visit Date ([b]EDL_VisitDate[/b])
Visit Start Time ([b]EDL_VisitStart[/b])
Visit End Time [b](EDL_VisitEnd[/b])
Visit Purpose ([b]EDL_Purpose[/b])
Class Code [b](EDL_Class_CD[/b])
In AREV, the default value for Purpose is set by a Symbolic called [b]{Deflt_Purpose}[/b]; Also, the [b]Class Code[/b] is only valid if the[b] Purpose[/b] is either "Training" or "Trainer". That is validated by a subroutine called "[b]Check_Visit[/b]" which validates that along with other pieces of information (such as the Time columns) prior to permitting the record to be saved. If there is an error, then an error message is displayed.
I need to set the[b] DefValue[/b] of the [b]Purpose[/b] column. It doesn't appear that I can do this with a Symbolic from the dictionary, so I need to do it with a stored procedure or some Event script. I see that [b]DefValue[/b] can get its value from a Function. i.e. [b]FUNCNAME('arg1',2,['arg3',3])[/b]
I need to know how to pass the data from the current record in the Window into the stored procedure or Event so that I can manipulate it. A simple example is: the [b]DefValue for Purpose[/b] can be the information that is stored in the "[b]FHC_Users[/b]" table for the displayed User ID, field # 3. e.g. [b]DefValue = Xlate ("FHC_Users", {User_ID},3,"X")[/b]. I then need to pass the correct value back to the [b]DefValue[/b] property for the Purpose column. It needs to go into [b]DefValue[/b] instead of directly into [b]Purpose[/b] since it is possible, under certain conditions, to choose something other than the [b]DefValue[/b].
I need to pass the record to the[b] Check_Visit[/b] subroutine which runs when the "[b]Write[/b]" button is clicked, but before the row is saved. If there is an error; Display the error; return to the record in the window to correct the error. (The [b]Check_Visit[/b] subroutine potentially runs multiple times until all errors are corrected i.e. each time "Write" is clicked.)
I suspect that there may be multiple ways to accomplish the above. Any guidance would be appreciated.
[b]This is the actual code from the symbolic "{Deflt_Purpose}":[/b]
[i]DFLT = {USER_DFLT_PURPOSE}; * A symbolic on the Visits Table, it's value is set as follows:
* ROLE=XLATE("FHC_USERS",{USER_ID},3,"X")
* @ANS=XLATE("ROLES",ROLE,2,"X") - This is the Default_Purpose column
UDFLT = DFLT
* DFLT begins as 'DEFAULT_PURPOSE' from ROLES Table
BTDATE = ICONV("03 JAN 19","DE"); * FIRST THURSDAY
BFDATE = BTDATE + 1 ; * FIRST FRIDAY
BSDATE = BTDATE + 3 ; * FIRST SUNDAY
* DATE is usually DATE(), as that is the default.
DATE = @RECORD<2>
TDDIFF = DATE-BTDATE
FDDIFF = DATE-BFDATE
SDDIFF = DATE-BSDATE
* TIME = TIME()
TIME = @RECORD<3>
TDFLAG = 0 ; * THURSDAY DATE FLAG
FDFLAG = 0 ; * FRIDAY DATE FLAG
SDFLAG = 0 ; * SUNDAY DATE FLAG
FTFLAG = 0 ; * FRIDAY TIME FLAG
ETFLAG = 0 ; * EVENING TIME FLAG
TFLAG = 0 ; * TIME FLAG
IF TIME >= 41400 AND TIME <= 61200 THEN TFLAG = 1
IF TIME >= 66600 THEN ETFLAG = 1
IF MOD(TDDIFF,7) = 0 THEN TDFLAG = 1
IF MOD(FDDIFF,7) = 0 THEN FDFLAG = 1
IF MOD(SDDIFF,7) = 0 THEN SDFLAG = 1
IF FDFLAG AND TFLAG THEN FTFLAG = 1
IF FDFLAG = 0 THEN FTFLAG = 0
IF UDFLT = 'YOUTH' AND ( FDFLAG = 0 OR FTFLAG = 0 ) THEN
DFLT = 'PATRON'
END
IF FDFLAG AND FTFLAG THEN
IF DFLT = "YOUTH" THEN
NULL
END ELSE
DFLT = UDFLT
END
END
IF TDFLAG AND ETFLAG AND DFLT <> "TRAINER" THEN
DFLT = "TRAINING"
END
IF TDFLAG = 0 AND ETFLAG THEN
DFLT = "GROUP"
END
IF SDFLAG THEN
DFLT = "GROUP"
END
@ANS = DFLT[/i]
[b]This is the actual code (AREV64) for the Check_Visits subroutine[/b]
[i]SUBROUTINE CHECK_VISITS
$INSERT SYSINCLUDE,WINDOW_COMMON%
DECLARE SUBROUTINE MSG
UID = @RECORD<1>
VSTART = @RECORD<3>
VEND = @RECORD<4>
VSECS = VEND - VSTART
PURPOSE = @RECORD<5>
CLASS = @RECORD<6>
ROLE = XLATE("FHC_USERS",UID,3,"X")
WARD = XLATE("FHC_USERS",UID,4,"X")
BEGIN CASE
CASE ROLE = 'STAFF' AND PURPOSE = 'YOUTH'
MSG ('"STAFF" must not be entered as "YOUTH" on the Friday program')
WC_VALID% = 0
CASE VEND > 0 AND VEND < VSTART
MSG ('Visit End Time must be after Visit Start,|Hint: Enter a "P" after the time for PM.|Press [F1] at the prompt for more information.')
WC_VALID% = 0
CASE VSTART < 21600
MSG ('Visit Start Time should be 6:00 AM or later.')
WC_VALID% = 0
CASE VSTART > 0 AND VSTART = VEND
MSG ('Visit start and End Time are the same.')
WC_VALID% = 0
CASE VSECS > 36000
MSG ('WARNING - visit exceeds 10 hours')
WC_VALID% = 0
CASE ( PURPOSE <> 'TRAINING' AND PURPOSE <> 'TRAINER' ) AND CLASS > 0
MSG ('Visit has invalid purpose|Or Class ID entered in error')
WC_VALID% = 0
CASE ( PURPOSE = 'TRAINING' OR PURPOSE = 'TRAINER' ) AND CLASS = ''
MSG ('Class # must be entered for Trainer/Training Visits.')
WC_VALID% = 0
END CASE
IF WARD = "NK" OR WARD = '' THEN
MSG ('Caution: WARD = "NK",|Please endeavor to find the correct ward.')
END
RETURN
END[/i]
----
=== At 04 MAY 2020 03:28PM rdhull50 wrote: ===
Rober Hull
Since writing this thread originally, I have learned a few things, and with some assistance, have resolved all of my issues on this topic.
I am now able to populate the defValue property with a function and my "Check_Visits" program is running as a Write-event on the Form.
I presume that the data in the controls on the form are converted into their internal stored format as part of the Write event and are thereby not accessible from the form itself. e.g. Dates are entered on the form in there external format and converted to an integer value during Write. So if you need to use the internal integer form of the date, then you need to use the Iconv statement. If there is some other way of directly getting at the converted value of a control, I would be happy to know it.
----
=== At 04 MAY 2020 03:30PM bob carten wrote: ===
Hi Robert,
The 'INVALUE' property should give you the internal value
----
=== At 07 MAY 2020 01:13PM rdhull50 wrote: ===
Can you tell me exactly what "DEFPROP" is, in terms of a data bound control in a Window (form)?
e.g. Get_Property( @Window : ".EDL_RECORDDATE" , "DEFPROP" )
where EDL_RECORDDATE is the control for a field of Data Type, "DATE".
How does it differ from:
Get_Property( @Window : "EDL_RECORDDATE" , "TEXT" )
which returns the textual value for the field (e.g. "30 APR 2020" ) and,
Get_Property( @Window : "EDL_RECORDDATE" , "INVALUE" )
which returns the internal (stored) value for the field (e.g. "19053" ).
----
=== At 07 MAY 2020 02:17PM Andrew McAuley wrote: ===
It's a conceptual difference. With DEFPROP you don't need to differentiate between the default data property for each control, TEXT vs CHECK vs VALUE etc. Also (and more importantly) when you set TEXT it updates the TEXT/DEFPROP property [i]but the system doesn't behave as though it were changed[/i] so won't for example, warn you if you attempt to leave the window immediately without saving (as the system thinks nothing has changed). When you set the DEFPROP property the system registers the change.
[url=https://www.sprezzatura.com]The Sprezzatura Group[/url]
[url=https://www.sprezzatura.com/blog]The Sprezzatura Blog[/url]
[i]World leaders in all things RevSoft[/i]
[img]https://www.sprezzatura.com/zz.gif[/img]
[[https://www.revelation.com/revweb/oecgi4p.php/O4W_HANDOFF?DESTN=O4W_RUN_FORM&INQID=WORKS_READ&SUMMARY=1&KEY=DE1A0F98E3B16E4F9C1962C4FDA5A2FB|View this thread on the Works forum...]]