fallguyjg
16th August 2005, 00:06
Baan Friends,

I'm creating a sales line via AFS, and I'm wanting to set the sales line position.
But the sales line position is auto generated, and ignores my assigned position.

I have form fields orno.f and pono.f
When I set the pono.f = 10, it ignores this value and creates a sales line with the next position (in my case, increment by 1).

Here's my code:


#define FAIL (err.cde = false)
#define NOT_FOUND (err.cde <> 1)

function insert.sline()
{
| find sales header
stpapi.clear("tdsls4101m000")
stpapi.put.field("tdsls4101m000", "tdsls040.orno", str$(orno.f))
err.cde = stpapi.find("tdsls4101m000", err.msg)
if FAIL then
stpapi.get.mess.code("tdsls4101m000", err.msg)
if isspace(err.msg) then
err.msg = "Record Not Found"
endif
while not isspace(err.msg)
message("%s", err.msg)
stpapi.get.mess.code("tdsls4101m000", err.msg)
endwhile
stpapi.recover("tdsls4101m000", err.msg)
stpapi.end.session("tdsls4101m000", err.msg)
return
endif
if NOT_FOUND then
message("Record Not Found")
stpapi.end.session("tdsls4101m000", err.msg)
return
endif

| add sales line
stpapi.handle.subproc("tdsls4101m000", "tdsls4105s000", "add")
stpapi.clear("tdsls4105s000")
stpapi.continue.process("tdsls4101m000", err.msg)
stpapi.put.field("tdsls4105s000", "tdsls041.pono", str$(pono.f))
stpapi.put.field("tdsls4105s000", "tdsls041.item", item.f)
stpapi.put.field("tdsls4105s000", "tdsls041.oqua", str$(oqua.f))
stpapi.put.field("tdsls4105s000", "tdsls041.pric", str$(pric.f))
err.cde = stpapi.insert("tdsls4105s000", true, err.msg)
if FAIL then
stpapi.get.mess.code("tdsls4105s000", err.msg)
while not isspace(err.msg)
message("%s", err.msg)
stpapi.get.mess.code("tdsls4105s000", err.msg)
endwhile
stpapi.recover("tdsls4105s000", err.msg)
stpapi.end.session("tdsls4105s000", err.msg)
stpapi.end.session("tdsls4101m000", err.msg)
return
endif
stpapi.get.field("tdsls4105s000", "tdsls041.orno", orno)
stpapi.get.field("tdsls4105s000", "tdsls041.pono", pono)
stpapi.end.session("tdsls4105s000", err.msg)
stpapi.end.session("tdsls4101m000", err.msg)
message("Sales Order Line: %s / %s Created", orno, pono)
}

Anyone have any ideas on this?

Thanks,
fallguyjg

mark_h
16th August 2005, 15:41
I do not think this has anything to do with the problem, but I believe the stpapi.clear("tdsls4105s000") should come after the continue. Do you have source to where you can check what is happening? I believe that the insert runs through some code that sets the line and over writes what you input. At this point not sure what else you can try.

dnnslbrwn
16th August 2005, 19:07
Possibly flip the order of the pono and item lines. The first line that starts the new session might come before the default values hit each field. Maybe by changing the order, it might work.

That said, I seem to recall having the same problem and just letting it go after spending a day or two fighting with it.

-Dennis

fallguyjg
16th August 2005, 23:21
Update,

I logged a baan case and here's the answer.
- - - - - - - - - -
The position number is automatically determined in the before.input section of
tdsls041.pono. For the standard Baan BOIs, changes were introduced to allow
setting it manually.

extern domain tcmcs.str132 boi.call
...
if api.mode then
import("boi.call", boi.call)
...
endif
...
if not api.mode or
( boi.call <> "tdboidll0005" and
boi.call <> "tdboidll500006" and
boi.call <> "tdboidll500031" and
boi.call <> "tdboidll320040") then
tdsls041.pono =
tdsls4102.find.position.number(tdsls041.orno,
0,
true)
endif

If you could set the boi.call variable to "tdboidll0005", then you can use that
functionality. I checked the script, this only affects the position number,
the delivery address code, and some error handling.
- - - - - - - - - -

My new code and it works!

extern domain tcmcs.str132 boi.call

form.1:
init.form:
. . . . .
boi.call = "tdboidll0005"

Also I was informed that the stpapi.clear() function is no longer needed, since it is done automatically after command calls.

fallguyjg

mark_h
17th August 2005, 16:12
Thanks for posting a solution. I wonder if the same works for purchase orders. Something I may try soon - if I find the time.

fallguyjg
18th August 2005, 17:44
Results of further testing:

Even though the proposed fix (or work around) of setting the boi.call variable to one of the BOI DLLs that is part of standard baan (ie. boi.call = "tdboidll0005") seems to work in this case (tdsls4102),

My further testing with doing this same thing for purchase lines (ie. boi.call = "tdboidll0008") does NOT work.

After examing the scripts, it appears that there are many conditions checked in the scripts for the boi.call variable equal to one of the standard baan BOI DLLs.

And this can cause undesired results, as in the case of purchase lines (tdpur4102), it just hung up.

And even in the case of the sales lines (tdsls4102), there are conditions happening due to boi.call = "tdboidll0005", that I might not want occurring.

- - - - - - - - -

My conclusion is, that unless you know exactly what the boi.call variable is controlling in the script, don't use it.

fallguyjg