baanguy2
15th June 2005, 21:57
I am trying to create an AFS script for logging hours and looks like I am missing something, guys help me here,

The parameter for the Hours Accounting Type (in HRA parameters) is set to Day/Employee).

script:

function afs.hra.records()
{
stpapi.put.field("tihra1101m000","tihra100.hrdt",str$(weekno)&str$(weekdno + 1)&str$(yearno))
stpapi.put.field("tihra1101m000","tihra100.emno",str$(empl))
rslt = stpapi.find("tihra1101m000",errm)

if rslt <> 1 then

stpapi.put.field("tihra1101m000","tihra100.hrdt",str$(weekno)&str$(weekdno + 1)&str$(yearno))
stpapi.put.field("tihra1101m000","tihra100.emno",str$(empl))
stpapi.put.field("tihra1101m000","tihra100.koht",str$(etol(tckoht.production)))
stpapi.put.field("tihra1101m000","tihra100.pdno",str$(tisfc001.pdno))
stpapi.put.field("tihra1101m000","tihra100.opno",str$(tisfc010.opno))
stpapi.put.field("tihra1101m000","tihra100.opcp",str$(etol(tcyesno.no)))
stpapi.put.field("tihra1101m000","tihra100.qucp","0")
stpapi.put.field("tihra1101m000","tihra100.qrjc","0")
stpapi.put.field("tihra1101m000","tihra100.pccp","0")
stpapi.put.field("tihra1101m000","tihra100.tano",str$(tisfc010.tano))
stpapi.put.field("tihra1101m000","tihra100.cwoc",str$(tisfc010.cwoc))
stpapi.put.field("tihra1101m000","tihra100.mcno",str$(mcno))
stpapi.put.field("tihra1101m000","tihra100.stdy",str$(etol(ltoe(weekdno))))
stpapi.enum.answer("tihra1101m000","tihras0044",tcyesno.no)
stpapi.put.field("tihra1101m000","tihra100.hrea",str$(shsfc001.mutm))
stpapi.put.field("tihra1101m000","tihra100.hrma",str$(shsfc001.rutm))
stpapi.put.field("tihra1101m000","tihra100.ckow",str$(shsfc001.cdis))

stpapi.insert("tihra1101m000",1,errm)
stpapi.enum.answer("tihra1101m000","tihras0071",tcyesno.no)
stpapi.end.session("tihra1101m000")
}

After the insert event I am getting an error "Employee's first date of employement is 01-01-05"

Please help me to find out what am I missing.

Thank You

mark_h
15th June 2005, 22:14
Not sure what causes the error, but I did notice that you have the answer to one of the questions after the insert. That should probably be before the insert.

baanguy2
15th June 2005, 22:17
Thank you Mark for the inputs.

That enum answer is for the exit event of the session as it asks whether to process hours or not.

Thanak you,

mark_h
15th June 2005, 22:19
Did you check this thread (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=5800&highlight=tihra1101)? Looks there was some code and issues discussed for this session.

baanguy2
16th June 2005, 20:32
I looked into the thread and tried the scripts given there, but still not working,
One more wierd thing is that when I do a stpapi.change.view the return value is '0', guys please help me with this, I am going crazy with this AFS !!!????


Thank you

mark_h
16th June 2005, 22:20
Do you have source? You may have to debug it to see what is going on with the API code. From reading the other thread it certainly does not sound like something easy to do. Maybe even rates a call to Baan.

lvdvelde
13th July 2005, 00:33
I had the same problem, it's caused by the simple fact that AFS is not supported on tihra1101m000 when you have the default startoption parameterized on day-order. But my users were very attached to this way of starting the session, so I couldn't change this permanently. So what I did is changing the original parametervalue (4) for tihra000.koha to 1 (week order), then start the AFS and then changing tihra000.koha right back into 4 (day order). Not very elegant, but effective.

I tried creating another (variant) session on tihra1101m000 with just 1 key (by week) but no luck. So updating the parametervalue seemed the only option. And it works.

Lex

Paul P
18th July 2005, 05:55
Hi Lex,

Ah, so there is part of Hours Accounting that just won't work under API? How did you get the information? If it's true, then I don't have to feel like an idiot 'cuz I tried unsuccessfully to control BaanERP Hours Accounting through API :)

Rgds,
Paul

lvdvelde
18th July 2005, 09:46
You can check Quick Guide 1824 on that.

Regards,

Lex

ulrich.fuchs
18th July 2005, 14:49
You are entering values like

str$(weekno)&str$(weekdno + 1)&str$(yearno)

into date fields.

AFS however requires for a date the numeric value of the date (as given by the date.to.num(...) or week.to.num() function)s, transferred as a String. So, try someting like

str$(week.to.num(weekno, yearno, weekdno+1)).

Hope that helps,

Uli

lvdvelde
18th July 2005, 15:08
I think the input for tihra100.hrdt is correct:


stpapi.put.field("tihra1101m000", "tihra100.hrdt", str$(wday) &
str$(wknm) &
str$(year))


The AFS expects you to insert the values just like a "real" user would do. The syntax above is working perfectly well for me.

Lex