Eddie Monster
7th December 2005, 22:23
I am fairly inexperienced with AFS, but I am trying to use it to automate the insertion of manually created commission lines. When I try to compile my code I receive an error message stating that there is an unresolved reference to stpapi.synchronize.dialog function.

Perhaps it isn't available for Baan IVc4?

Can anyone confirm? - and if this particular function is not available in Baan IVc4, how would I accomplish the insert using AFS?


function insert.incentive.payment.line()
{
domain tcmcs.str100 error.msg
domain tcmcs.long return.value

stpapi.clear("tdcms0150m000")
stpapi.put.field("tdcms0150m000","tdcms050.orno", str$(ws.orno))

return.value = stpapi.change.view("tdcms0150m000", error.msg)

if return.value = 1 then
return.value = stpapi.synchronize.dialog("tdcms0150m000", "add", error.msg)
if return.value then
stpapi.put.field("tdcms0150m000","tdcms050.pono", str$(ws.pono))
stpapi.put.field("tdcms0150m000","tdcms050.reln", str$(ws.reln))
| stpapi.put.field("tdcms0150m000","tdcms050.sern", "2")
stpapi.put.field("tdcms0150m000","tdcms050.cmpr", str$(ws.incentive.pctg))
stpapi.put.field("tdcms0150m000","tdcms050.grpc", "0")
stpapi.put.field("tdcms0150m000","tdcms050.amnt", str$(invoice.amount))
stpapi.put.field("tdcms0150m000","tdcms050.amta", "0")
stpapi.put.field("tdcms0150m000","tdcms050.crtp", "200")
stpapi.put.field("tdcms0150m000","tdcms050.lacd", "73040")
stpapi.put.field("tdcms0150m000","tdcms050.lacc", "32020")
stpapi.put.field("tdcms0150m000","tdcms050.resv", "1") | Reserve = "Yes"
stpapi.put.field("tdcms0150m000","tdcms050.ttyp", ws.ttyp)
stpapi.put.field("tdcms0150m000","tdcms050.invn", str$(ws.invn))
return.value = stpapi.insert("tdcms0150m000", true, error.msg)
if not return.value then
return.value = stpapi.recover("tdcms0150m000", error.msg)
endif
endif
endif

stpapi.end.session("tdcms0150m000")

}

Eddie Monster
7th December 2005, 22:49
Do I need to define anything other than:

#pragma used dll ottstpapihand

?

lbencic
7th December 2005, 23:09
Right, that's not a Baan IV command (Synchronized dialogs are Baan V and LN specific). Synchronization is used when they have a multi occurance 'overview' session, and they double click on the record to get a single occurance 'detail' session. Since your tdcms0150m000 session is just a single session (multiple screens is ok), you should not need the sync command or anything similar in Baan IV. The basic flow is just Change the View, then fill the details, then Insert the record, just as you have but without the sync. That said, I have not worked on the tdcms0150m000 session, so I don't know any specifics about that one.

Good luck, let us know if it works without the syncronize.

Eddie Monster
8th December 2005, 22:29
Here is the code that worked.

function insert.incentive.payment.line()
{
domain tcmcs.str100 error.msg
domain tcmcs.long return.value

stpapi.clear("tdcms0150m000")
stpapi.put.field("tdcms0150m000","tdcms050.type", "1") | Type = Commission
stpapi.put.field("tdcms0150m000","tdcms050.orno", str$(ws.orno))

return.value = stpapi.change.view("tdcms0150m000", error.msg)

if not isspace(strip$(error.msg)) then
message(error.msg)
endif

stpapi.put.field("tdcms0150m000","tdcms050.pono", str$(ws.pono))
stpapi.put.field("tdcms0150m000","tdcms050.reln", str$(ws.reln))
stpapi.put.field("tdcms0150m000","tdcms050.sern", "2")
stpapi.put.field("tdcms0150m000","tdcms050.cmpr", str$(ws.incentive.pctg))
stpapi.put.field("tdcms0150m000","tdcms050.grpc", "0")
stpapi.put.field("tdcms0150m000","tdcms050.amnt", str$(invoice.amount))
stpapi.put.field("tdcms0150m000","tdcms050.amta", "0")
stpapi.put.field("tdcms0150m000","tdcms050.crtp", "200")
stpapi.put.field("tdcms0150m000","tdcms050.lacd", "73040")
stpapi.put.field("tdcms0150m000","tdcms050.lacc", "32020")
stpapi.put.field("tdcms0150m000","tdcms050.resv", "1") | Reserve = "Yes"
stpapi.put.field("tdcms0150m000","tdcms050.ttyp", ws.ttyp)
stpapi.put.field("tdcms0150m000","tdcms050.invn", str$(ws.invn))
return.value = stpapi.insert("tdcms0150m000", true, error.msg)
if not return.value then
return.value = stpapi.recover("tdcms0150m000", error.msg)
endif

stpapi.end.session("tdcms0150m000")

}

I have a question though... in my code test i hardcoded the tdcms050.sern value to "2" because I knew that for my record that was the next sequence number. If I were to go into the session and simply insert the record manually, Baan suggests the 2 as the next consecutive sequence number. Can I omit the stpapi.put for tdcms050.sern so that Baan will automatically fill it in or do I need to create query to get the last used .sern and increment it by one?

mark_h
9th December 2005, 00:07
I have had problems with sern before, in most cases I have been able to leave in blank and just do the insert. I can not remember which would where I had to go look up the last used sern. So try it by leaving it blank - I think it will work.

Francesco
9th December 2005, 00:54
The important thing to remember is that AFS will apply all available session-logic (unless the session specifically excludes certain elements for AFS).
So as a rule of thumb, if your manual process does not require you to enter a number in a field, you don't have to worry about it in AFS either.

In the case of tdcms0150m000, you'll find that the session will automatically enter the next sequence number (sern), so it is safe to assume that your AFS will do the same thing when it touches the .sern field.

Eddie Monster
9th December 2005, 14:36
I have tried it without the 'sern' value and the afs run does insert the record with the proper value.

We are just beginning to use afs and are now starting to realize the power behind the functionality. I hope to use it much more in the future.

Thanks to you all for your assistance!