jhargett
3rd August 2009, 19:23
I am having a problem using AFS to populate the subsession tdsls4103s000 which allows adding a special delivery address to the Sales Order header. After filling out the Sales Order header and saving it, then storing the returned Sales Order number, this function is called:


function long save_delivery_address()
{
long ret
string last_error(255)
string msg(255)

last_error = ""
output("Handle Subsession for Delivery Address: " & del_session)
stpapi.handle.subproc(main_session, del_session, "add")
stpapi.application.option(main_session, 1, 2, last_error)
if (last_error = "") then
output("ERROR: Could not start subsession for delivery to address:" & last_error)
return (0)
endif

stpapi.put.field( del_session, "tdsls042.orno", str$(orno) )
ccty = "USA"
stpapi.put.field( del_session, "tdsls042.ccty", ccty )
ret = stpapi.update( del_session, false, last_error)
if (ret = 0) then
output("ERROR: Could not update data to subsession for delivery to address:" & last_error)
return (0)
endif

stpapi.get.field( del_session, "tdsls042.nama", msg )
output("Value of Nama: " & msg)
stpapi.put.field( del_session, "tdsls042.nama", nama )
stpapi.get.field( del_session, "tdsls042.nama", msg )
output("Value of Nama: " & msg)
stpapi.get.field( del_session, "tdsls042.orno", msg )
stpapi.put.field( del_session, "tdsls042.namb", namb )
stpapi.put.field( del_session, "tdsls042.namc", namc )
stpapi.put.field( del_session, "tdsls042.namd", namd)
stpapi.put.field( del_session, "tdsls042.name", name )
stpapi.put.field( del_session, "tdsls042.namf", namf )


ret = stpapi.insert( del_session, true, last_error)
if (ret = 0) then
output("ERROR: Could not insert to subsession for delivery to address:" & last_error)
return (0)
endif
stpapi.end.session(del_session)
output("End Subsession for Delivery Address")
return (1)
}


The program returns an error after the stpapi.insert that says "Country not found in the Countries table". This is the error you get in the session if you try to leave the country field blank, but as you can see, I am setting the ctty field to "USA", which is a valid country in the countries table. Normally, when you pull up this session in Baan, all of the fields are filled out with the default delivery address of the customer. It seems when I pull up the session using AFS, these fields are not filled out. That makes it seem like maybe some initialization is not happening. I tried resolving that by adding the stpapi.update call to call the field sections, but it didn't seem to work. Any suggestions?

mark_h
4th August 2009, 23:00
Is there a main session you can run versus the subsession? That would be the easiest solution.

Next - does this "stpapi.application.option(main_session, 1, 2, last_error)" actually start the subsession? In debug mode check the processes - before and right after this statement. You should see the subsession started - if not, that could explain why those other fields are not filled correctly. Do you own source so you can see what is happening between main and sub-sessions?

jhargett
4th August 2009, 23:16
No, I didn't see a main session that would do the same thing.

The subsession does actually start but not until the first put statement.

I do have source code for session tdsls4103s000 but I can't put it in debug mode because it doesn't compile. It seems I am missing some other object.

Thanks for the reply.

mark_h
5th August 2009, 18:13
The subsession does actually start but not until the first put statement.

Then I think that is the initial problem you will have to overcome. So is this subsession choice.user.x option on the form? On my system just glancing at the form it is choice.user.1 - which would make the command stpapi.application.option(main_session, 1, 1, last_error). Can you confirm this on your system.

jhargett
5th August 2009, 18:23
The first thing under the Application menu is Lines. That is started by the stpapi.continue.process. So, I assume that stpapi.application.option handles everything after that. The next menu option after lines on my system is Maintain Specific Postal Address. I want the 2nd menu option though, which is Maintain Specific Delivery Address. So, am I right in using 2 as the third parameter?

As far as when the subsession starts, I thought it was normal to start after the put. After all, there is no command to start a main session, the session just starts after the first put statement.

mark_h
5th August 2009, 20:55
The first thing under the Application menu is Lines. That is started by the stpapi.continue.process. So, I assume that stpapi.application.option handles everything after that. The next menu option after lines on my system is Maintain Specific Postal Address. I want the 2nd menu option though, which is Maintain Specific Delivery Address. So, am I right in using 2 as the third parameter?
Check the form to see which user option it is - on my system it is choice.user.1. Which would result in the command I showed.

As far as when the subsession starts, I thought it was normal to start after the put. After all, there is no command to start a main session, the session just starts after the first put statement.
Sub-sessions and main sessions are not the same. Yes - a main session is activated with a put command. That starts the session for input. Sub-sessions are usually activited via an action command(insert, update, continue, application.option) on the main session. When those commands are executed that is when the subsession is fired up. That is how main sessions control sub-sessions. In this case the put is executing outside the control of the main session - which means the sub-session does not have any of the table or global variables required upon its activation. This is why when you look at the process id's using option dialog box - the sub-session parent id should be the main sessions NOT the session with the stpapi code in it.

jhargett
5th August 2009, 22:04
I think I am starting to get it :) You, of course, were right about the session not starting until the put statement. The session was starting up but the parentid was the one with the stpapi code.

I wasn't aware that there was a way to check which user option number to use. I looked at the Maintain Sales Order session and went to forms and then the "Spec. Options" button. it shows user.0 is the Specific Postal Address and user.1 is Maintain Specific Delivery Address. So I guess I need to use 1 there.

I changed it to 1, and debugged the session again, but the session is still not starting up as soon as the stpapi.application.option is called. It doesn't start until the first put or get call and then the PPID is still the STPAPI session and not Maintain Sales Orders.

jhargett
5th August 2009, 22:24
Also, wanted to note that I am not getting the same error message. I now get the error:
"Sales order not found"

It seems I have the exact same problem as has been brought up in this thread:
showthread.php?t=15152 (http://www.baanboard.com/baanboard/showthread.php?t=15152)

but doesn't seem to be a problem for this user:
showpost.php?p=100629&postcount=5 (http://www.baanboard.com/baanboard/showpost.php?p=100629&postcount=5)

jhargett
5th August 2009, 22:31
It works now! I had to use the function stpapi.zoom.option instead of stpapi.application.option. What is the difference between these two?

mark_h
6th August 2009, 00:28
The difference is that stpapi.application.option is for executing a choice.user.x option. Stpapi.zoom is for zooming to a session off the menu on the special option. In theory you should be able to use either method to execute a choice.user.x option. BUT if the special zooms to a menu which allows you to select a subsession- then you need to use the stpapi.zoom option and the subsession you enter must be on the menu.