gous99
11th July 2002, 21:42
Hi,
I'm trying to make an AFS for the session Maintain Hours Accounting.
I put my view fields, then set.view, then insert my values and do an insert. It always returns me the message "Day not allowed". I ran my script with the afs.log file, my problem is tihra100.dayn, which get it's value in the section after.field of tihra100.hrdt.
So after I put the value in the tihra100.hrdt field, I do a get.field on tihra100.dayn, it returns the correct value, but when I do the insert, I get the message, and do a get.field again on tihra100.dayn, and it is now returning 0.
It seems like the insert, or save doesn't keep the value of this field. Does anyone has an idea on what can be wrong here? Here is my code.
stpapi.put.field("tihra1101m000", "tihra100.year", str$(year.f))
stpapi.put.field("tihra1101m000", "tihra100.week", str$(week.f))
stpapi.put.field("tihra1101m000", "tihra100.emno", str$(emno.f))
ret.val = stpapi.change.view("tihra1101m000")
stpapi.put.field("tihra1101m000", "tihra100.koht", str$(g.koht))
stpapi.put.field("tihra1101m000", "tihra100.pdno", str$(g.pdno))
stpapi.put.field("tihra1101m000", "tihra100.opno", str$(g.opno))
stpapi.put.field("tihra1101m000", "tihra100.tano", str$(g.tano))
stpapi.put.field("tihra1101m000", "tihra100.cwoc", g.cwoc)
stpapi.put.field("tihra1101m000", "tihra100.stdy", str$(g.stdy))
stpapi.put.field("tihra1101m000", "tihra100.endy", str$(g.endy))
stpapi.put.field("tihra1101m000", "tihra100.hrea", str$(g.hrea))
stpapi.put.field("tihra1101m000", "tihra100.ckow", g.ckow)
stpapi.put.field("tihra1101m000", "tihra100.opcp", str$(g.opcp))
stpapi.put.field("tihra1101m000", "tihra100.qucp", str$(g.qucp))
stpapi.put.field("tihra1101m000", "tihra100.qrjc", str$(g.qrjc))
stpapi.put.field("tihra1101m000", "tihra100.hrdt", str$(g.hrdt))
stpapi.get.field("tihra1101m000", "tihra100.dayn", s.dayn) (HERE THE VALUE IS CORRECT)
stpapi.insert("tihra1101m000", 1, gapi.error.code)
stpapi.get.field("tihra1101m000", "tihra100.dayn", s.dayn) (HERE THE VALUE IS 0)
if isspace(gapi.error.code) then
stpapi.save("tihra1101m000", gapi.error.code)
if not isspace(gapi.error.code) then
message("The error is : " & gapi.error.code)
else
stpapi.enum.answer("tihra1101m000", "tihras0071", tcyesno.no)
endif
else
message("The error is : " & gapi.error.code)
endif
stpapi.end.session("tihra1101m000")
mark_h
12th July 2002, 00:02
If you own source the best solution is to put the tihra1101m000 session in debug mode and trace through it.
Some things to try:
(1) What you might try is to include tihra100 in your function server code, set tihra100.dayn. Then do the insert. Just a wild guess. I had to do this for a field in my manual transfer function server.
(2) Try a stpapi.insert("tihra1101m000", 0, gapi.error.code), followed by a stpapi.save. I had to do this on my MAUC function server. For some reason if I did a new item/project/mauc record a insert with a 1 always returned an error. So something in the db.update section was not working, but a insert with a 0 mode followed by a save did work. It took several hours and several attempts to insert a new mauc record. No matter what I tried to input the dollars I had to do stpapi.insert(0 mode), stpapi.save, then a stpapi.find to get the cpc code I inserted, then a update to get dollars in it. It would not let me do it all at once with just a insert.
These are just wild guesses from my experience with function server code. Since we do not own source it can take hours sometimes to figure out what really needs to be done to get the code to work. Also I would try #2 first, #1 may not work since the insert appears to set the field to 0. Also does the tihra100 table have a 0 in the tihra100.dayn field?
Good Luck!
Mark
lbencic
12th July 2002, 00:16
Gous -
I wrote a version of Hours Accounting via stpapi which I have since removed. I did not have any issues with the dayn, and only had to enter the fields I would have entered in the session. The one problem I did have (and I don't remember what error it sent me) is that I could not start off by inserting a closed record with an end time. What I had to do was insert the record as 'active', with just the start date/time and save. Then, re-find the record and update it to 'closed' and put in the end date/time, elapsed hours.
What version of Baan are you on and do you have the latest updates? As I look through the source code (tihra1101 in stnd VRC for Baan 4c), I see that there is a patch for boi's directly effecting the dayn logic. Solution number 114660 specifially deals with the dayn in api mode - do you have that ident? My version goes through Solution #119293 which also has api related code. It is an area of hot activity for them, so make sure you have the latest version.
Also, I found that doing a get field while doing the put fields does not get the value based on the puts. The puts are not executed, do nothing in the session, until you choose insert/save. They are not put into the field and execute the after field sections. All the after field sections and the choice sections are execute on the insert/save command. Even when you have executed the save, you have to re-look up your record and do the 'gets' to find the current field information as the session sees it.
You can see this if you have source code and put the session in debug. The first 'put' call you make does Open the session by calling the before program and init form sections, but the check input and other field sections do not get called until a save of some sort is done (including change view, etc.).
Hope something in there helps. Good luck!
NvanBeest
18th June 2003, 21:12
Hi Gous
Did you solve this in the end? Any other special issues regarding tihra1101 that you can tell us?
And another issue regarding this session (using BaanIVc4): I see that, when entering a worktime table, the next field is the end-time. When jumping back to the start-time, the hours are calculated. Then, entering new values for start and end times result in the question whether the hours have to be recalculated. How can this be handled using AFS?
Regards,
Nico
lbencic
18th June 2003, 22:18
You can use the stpapi.anum.answer to set the answer to any question the way you want - does that help?
NvanBeest
18th June 2003, 22:38
Somewhat, thanks. But if the start and end time result in the same number of hours, the question does not pop up. So how do I check whether the question is there or not?
Regards
Nico
lbencic
18th June 2003, 22:47
You don't have to know the timing, or if it comes up at all. The stpapi.set.enum will just store your setting, and answer that question any time it comes up the way you set it to. API's handle questions very well - even if you don't do the stpapi.set.enum it will take the default answer to any question and continue.
bemisgrm
31st July 2003, 23:26
I also have been developping a function server for hour accounting for Baan 5b. I had a similiar problem with this date/time field. The problem was that tihra100 did not hold values for year and week, so the test in tihra1101s000 was alway's going wrong. The solution to that is write a functionserver for tihra1501m000 (the session where 1101 is called from) and call the tihra1101s000 sessionfrom there
NvanBeest
31st October 2003, 15:35
Herewith the code that works for me in BaanIV.
|* Before calling this function, you need to calculate the week and day
|* numbers with the function num.to.week()
function long insert_hours( long year,
long wknm,
domain tcemno emno,
domain tckoht koht,
domain tctano tano,
domain tcorno orno,
long wday,
domain tcmcs.str4 stim,
domain tcmcs.str4 etim)
{
double tdif | Difference in time
double tchk | Controlvalue
long rslt | Result (of function)
string fldv(30) | Field value for stpapi.get.field()
string errc(256) | Errormessage
string errs(256) | Errormessage from AFS
|* Calculate the difference in time
tdif = hhmmtodec(etim) - hhmmtodec(stim)
tchk = round(tdif, 3, 0)
|* Fill the header values in tihra1101m000
stpapi.end.session("tihra1101m000")
stpapi.put.field("tihra1101m000", "tihra100.year", str$(year))
stpapi.put.field("tihra1101m000", "tihra100.week", str$(wknm))
stpapi.put.field("tihra1101m000", "tihra100.emno", str$(emno))
rslt = stpapi.change.view("tihra1101m000", errs)
if rslt then
|* Check whether the header has to be redone (if not exact find)
if rslt = 2 then
stpapi.put.field("tihra1101m000", "tihra100.year", str$(year))
stpapi.put.field("tihra1101m000", "tihra100.week", str$(wknm))
stpapi.put.field("tihra1101m000", "tihra100.emno", str$(emno))
endif
stpapi.put.field("tihra1101m000", "tihra100.hrdt", str$(wday) & str$(wknm) & str$(year))
stpapi.put.field("tihra1101m000", "tihra100.dayn", str$(wday))
stpapi.put.field("tihra1101m000", "tihra100.koht", str$(etol(koht)))
|* This is for serviceorders, where the ordernumber has to be filled
|* For other types, you will have to fill the correct fields
if koht = tckoht.service then
stpapi.put.field("tihra1101m000", "tihra100.pdno", str$(orno))
endif
stpapi.put.field("tihra1101m000", "tihra100.tano", str$(tano))
stpapi.put.field("tihra1101m000", "tihra100.cwtt", params_wttab)
stpapi.put.field("tihra1101m000", "tihra100.stdy", str$(wday))
stpapi.put.field("tihra1101m000", "tihra100.sttm", stim)
stpapi.put.field("tihra1101m000", "tihra100.entm", etim)
if tchk <> tdif then
stpapi.put.field("tihra1101m000", "tihra100.hrea", sprintf$("%.3f", tdif))
endif
if not stpapi.insert("tihra1101m000", 0, errs) then
while true
errc = stpapi.get.mess.code("tihra1101m000", errs)
if isspace(errs) then
break
endif
endwhile
stpapi.recover("tihra1101m000", errs)
stpapi.end.session("tihra1101m000")
return(-1)
endif
|* Fix the date and daynumber before actual saving
stpapi.put.field("tihra1101m000", "tihra100.hrdt", str$(wday) & str$(wknm) & str$(year))
stpapi.put.field("tihra1101m000", "tihra100.dayn", str$(wday))
|* Now save the record
if not stpapi.save("tihra1101m000", errs) then
while true
errc = stpapi.get.mess.code("tihra1101m000", errs)
if isspace(errs) then
break
endif
endwhile
stpapi.recover("tihra1101m000", errs)
stpapi.end.session("tihra1101m000")
return(-1)
endif
endif
stpapi.end.session("tihra1101m000")
return(0)
}
function double hhmmtodec(domain tcmcs.str4 stim)
{
|* This function converts a time value (HHMM) to decimal
double rslt | Result (of function)
rslt = val(stim(1;2)) + (val(stim(3;2)) / 60)
return(rslt)
}
function domain tcmcs.str4 dectohhmm(double dtim)
{
|* This function converts a decimal time to a time value (HHMM)
return(sprintf$("%04d", round(dtim,0,0)*100 + (dtim-round(dtim,0,0))*60))
}
lbencic
4th November 2003, 19:08
I will only add that you need to pay attention to the Parameter for Hours Accounting view - if they view by week or by day, the setup fields are different and have to be filled different before the change.view. This caused me problems on my first development, I developed using the 'week' view, and the customer had the daily view and I had to update my code.
zardoz
11th December 2003, 13:26
I have the same problem. Debugging the tihra1101 script called by my script, it seems that tihra100.stdy is reset to empty value after a while. I have put a trace on this variable but the value changes to 0 when it jumps to the check.input section of this field...
I've the 114660 solution, but it seems it works only if called thru boi...
I'm seroiusly thinking to avoid the use of afs and try to write a DLL that does this works, but... the script is almost 8000 lines!
NvanBeest
11th December 2003, 14:31
Hi Zardos
Have you tried the "fooling" of the AFS like I do, setting the field again between insert/update and actual save?
lbencic
11th December 2003, 17:57
Hours accounting can be done through AFS. There can be a lot of issues but just on start up. I'm assuming you followed the other active thread about translating the start day to the correct value, not always the value returned by num.to.week...
http://www.baanboard.com/baanboard/showthread.php?s=&threadid=1524&highlight=tihra100.stdy
If it's working through boi, not your, try putting the following in:
1. declare:
extern domain tcmcs.str132 boi.call
Then, before your afs calls, put:
boi.call = "tiboidllbit001"
Hope that helps. Let us know.
zardoz
11th December 2003, 18:22
I'll try both the suggestions just next monday when I'll go to the customer site...
Thank you for now, Nico and Ibencic.
zardoz
15th December 2003, 12:36
I've tried the Ibencic solution, but it wasn't enough...
So I added a
extern domain tcmcs.str132 boi.call
extern long boi.week.day.no
and:
boi.call = "tiboidllbit001.create"
and assigned to boi.week.day.no the correct value.
After that, I have modified some of tihra1101 because some action required was put in when.field.changes section instead of check.input, so the AFS cannot access correctly...
But, if I haven't the script of tihra1101 it was almost impossible to succeed
:D
Thanks all again
lbencic
15th December 2003, 17:21
Zardoz -
I see the boi.week.day.no there now too, sorry I missed posting that. I do think it is more difficult now that they are adding the boi.call variable in a lot of scripts, and making it difficult to write an afs without having the source. This is becoming more common in the Baan code unfortunately.
What logic in the 'when.field.changes'? I have not had to update our hra1101 code for that reason... (ok, other reasons :) ). One thing I did have to do in various different Service Pack versions was change the field order on the form.
As a general note (read: sales pitch, so take as you will), we use many different methods here. If the afs won't work for a reason such that you mentioned (not firing the when field changes when you need it to) you can try the wrapper methods - RMCgen/QKEY/Rush. Using those methods, you have direct control of calling each section. They also don't run in api mode, so the differences sometimes make the wrapper solution a better fit for what you are doing. The wrapper generators (at least our version) make using them just about as easy as afs.
Anyway, good luck - Hours Accounting is a bear, you've come a long way.
zardoz
16th December 2003, 16:23
I agree that hours accounting is a bear, but I think I have it's skin on my carpet now ;) The script now is working.
The AFS I wrote is a part of a set of interfaces between Wonderware and BaaN.
Sure, I haven't used Openworld - too expensive and also needs a lot of development work to keep it running. I simply added some interfaces tables to BaaN, without any reference to avoid problems, and people working on Wonderware side reads&write them using Oracle, and then run some VBS scripts calling via OLE the Baan interface functions collected in a DLL, so all the interfaces are really 'REAL TIME'...
All the other parts really weren't a big problem (Transferring production orders, stock transactions, reporting qties completed, etc)...
Thank you Lisa
Ps.: I've not fired the when.field.changes, I've only added in the check.field section the same logic only if api.mode is true.
tnzabo
1st December 2010, 15:26
Is anyone willing to post their entire working AFS code for the Enter Hours Accounting session? I'm in a crunch and am pretty sure I'm going to have to work through all these same issues.
Much thanks in advance!! Thank You!
NikkiZ