Baanman_2
26th August 2010, 12:48
I am trying to get a simple PO line insert through AFS. The headers can be input through AFS no problem, I seem to be missing something when it comes to sync dialog.

Manually all I need to input is item, qty and price.

Code I have is :-

stpapi.put.field("tdpur4500m000","tdpur400.orno",orno_str)
ret_stapi = stpapi.find( "tdpur4500m000" , err.msg )

ret_stapi = stpapi.change.view("tdpur4501m000", err.msg)
ret_stapi = stpapi.synchronize.dialog("tdpur4501m000", "add", err.msg)

stpapi.put.field("tdpur4101s000","tdpur401.item.segment.1",item(1;9))
stpapi.put.field("tdpur4101s000","tdpur401.item.segment.2",item(10;38))
stpapi.put.field("tdpur4101s000","tdpur401.oqua",str$(oqua))
stpapi.put.field("tdpur4101s000","tdpur401.pric",str$(pric))

ret_stapi = stpapi.insert("tdpur4501m000",true,err.mess)

if not ret_stapi
then
stpapi.recover("tdpur4101s000", return.msg)
endif

stpapi.end.session("tdpur4101s000",err.mess)
stpapi.end.session("tdpur4501m000",err.mess)
stpapi.end.session("tdpur4500m000",err.mess)

The return values for the find, synchronize and insert are all 1.

:confused:

mark_h
26th August 2010, 16:06
What version of baan is this? What are the sessions that need to be sync'ed up? Just from glancing at your code I can see issues - but I only work on 4c4 so my recommendations may not work on other versions. I am also assuming the tdpur4501m000 session is actually a subsession(not a main session which could be called independently) to the tdpur4500m000 session.


| This activates the tdpur4500m000 session and finds the order.
stpapi.put.field("tdpur4500m000","tdpur400.orno",orno_str)
ret_stapi = stpapi.find( "tdpur4500m000" , err.msg )
| Next what command in tdpur4500m000 activates the lines session-tdpur4501m000?
| In 4c4 it is the continue command so I would do this:
stpapi.handle.subproc( "tdpur4500m000", "tdpur4501m000", "add" )
stpapi.continue.process( "tdpur4500m000", fserr )
| Now the above continue could be the stpapi.form.command for other versions of baan.
| The above stpapi.subproc command lets tdpur4500 control the subsession(tdpur4501m000)
| Typically these type commands do not require a find, but it depends on how this works manually.

ret_stapi = stpapi.synchronize.dialog("tdpur4501m000", "add", err.msg)
stpapi.put.field("tdpur4101s000","tdpur401.item.segment.1",item(1;9))
stpapi.put.field("tdpur4101s000","tdpur401.item.segment.2",item(10;38))
stpapi.put.field("tdpur4101s000","tdpur401.oqua",str$(oqua))
stpapi.put.field("tdpur4101s000","tdpur401.pric",str$(pric))
ret_stapi = stpapi.insert("tdpur4501m000",true,err.mess)

stpapi.end.session("tdpur4101s000",err.mess)
stpapi.end.session("tdpur4501m000",err.mess)
stpapi.end.session("tdpur4500m000",err.mess)


Typically the way I do these sessions is to map them out like this.
(1) Start session x
(2) hit find button
(3) type in order click ok - correct order found
(4) Click continue
(5) Subsession x starts on order found
(6) Hit insert
(7) Put fields a,b,c let other fields default. Record inserted okay.
(8) Close subsession
(9) Close mainsession
Next I can map it to stpapi commands. I know for example 1,2,3 can be covered with a put.field and stpapi.find so on and so fourth.

With you code I see you start tdpur4500m000 and then separately start tdpur4501m000 - nothing to tie the two together. I can't speak for your version, but this is how 4c4 would work. If tdpur4501m000 is actually a main session then I could see where the insert could work and return a 1 value - you start the session change.view, sync it then start inserting. So what ever PO or record it started on now has a new line and not the PO you intended.

Baanman_2
26th August 2010, 18:54
Thanks Mark. This was for Baan V. As you pointed out, the call to tdpur4100m000 was not required. I have removed that and done the find on tdpur4501m000.
Record inserted properly.

Thanks again.

mark_h
26th August 2010, 19:43
Glad it worked. It is not always that easy. :)