Neal Matthews
6th April 2010, 14:54
Hello,

Writing my first API with the complication of a sub session and things are not going to plan.

After answering the second question in tdpur4120m0000 as a No the main session automatically calls the session tdpsc0191s000.

However in my API I cannot get tdpsc0191s000 to be active and when trying an update in tdpsc0191s000 I receive a message "Session not available" which means I must be doing something wrong when activating the subprocess. Can anybody see what ?

Cheers
Neal

| Start creating a receipt
stpapi.put.field("tdpur4120m000", "tdpur045.reno", "4")

|* Handle question tdpur41206 yes
ret=stpapi.enum.answer( "tdpur4120m000", "tdpur41206", tcyesno.yes )

stpapi.put.field("tdpur4120m000", "form.dino", "TEST")
stpapi.put.field("tdpur4120m000", "tdpur045.suno", "F073")

|* Handle question tdpur41207 no
ret=stpapi.enum.answer( "tdpur4120m000", "tdpur41207", tcyesno.no )

stpapi.handle.subproc("tdpur4120m000", "tdpsc0191s000", "add")

stpapi.put.field("tdpsc0191s000", "tdpsc910.mark", str$(1))
ret=( stpapi.update( "tdpsc0191s000", true, error ) )
message(error)

mark_h
6th April 2010, 16:08
Well I can't say for sure since I am unfamiliar with using this method to create a receipt. I would expect you need to execute a command on tdpur4120m000 to get this tdpsc0191 session activated. You can try update, save or maybe change.view. My code is really simple and I create a receipt for the complete purchase order:

| Creating a receipt always use 0 for the tdpur045.reno field.
msg = ""
stpapi.handle.subproc("tdpur4120m000","tdpur4224s000","add")
stpapi.put.field("tdpur4120m000","tdpur045.reno",str$(0))
rc = stpapi.change.view("tdpur4120m000",msg)
if not isspace(msg) then
stpapi.end.session("tdpur4120m000")
return(receipt.number)
endif

| Always use tdpur4224s000 to create receipt for all lines.
stpapi.put.field("tdpur4224s000","form.orno",str$(purchase.order))
stpapi.continue.process("tdpur4224s000",msg)
stpapi.end.session("tdpur4224s000")
if not isspace(msg) and strip$(msg)<> "Process is gone" then
stpapi.end.session("tdpur4120m000")
return(receipt.number)
endif
msg = ""

If you notice the stpapi.change.view activates the tdpur4224s000 session. Something like that might work for you.

Neal Matthews
7th April 2010, 01:37
Hello Mark,

Thanks for that (again). Now making progress in that I can see that the sub session is being called through looking at the shell. However after setting the Mark field in the session to "Yes" a save and exit from the session should set the order number and the item in the main session but I don't think the code is doing this. Any suggestions on how I can get the sub session to return these values or test for their existance ?

Cheers Neal

| Start creating a receipt
stpapi.put.field("tdpur4120m000", "tdpur045.reno", "4")

|* Handle question tdpur41206 yes
ret=stpapi.enum.answer( "tdpur4120m000", "tdpur41206", tcyesno.yes )

stpapi.put.field("tdpur4120m000", "form.dino", "TEST")
stpapi.put.field("tdpur4120m000", "tdpur045.suno", "F073")

|* Handle question tdpur41207 no
ret=stpapi.enum.answer( "tdpur4120m000", "tdpur41207", tcyesno.no )

|* Activate sub process
stpapi.handle.subproc("tdpur4120m000", "tdpsc0191s000", "add")
message(error)

ret = stpapi.change.view("tdpur4120m000",error)

stpapi.put.field("tdpsc0191s000", "tdpsc910.mark", str$(1))
stpapi.continue.process("tdpsc0191s000",error)
message(error)
stpapi.end.session("tdpsc0191s000")

stpapi.get.field( "tdpur4120m000", "tdpur045.item", error )
message(error)
stpapi.end.session("tdpur4120m000")

mark_h
7th April 2010, 16:10
So manually when the tdpsc0191s000 session comes up you enter yes then hit the save and exit button? I can think of a few things to try, but since I am not familiar with the session they are just guesses. Okay - you might want to just try a save before the continue. Not sure if that will work - next try a find on the tdpsc0191s000 session, then put the mark field, then (maybe save) and continue. From looking at the form on my session I see a multi-occurence session. I have found that sometimes a find pulls in the current record - even though it would be the only record on the screen. In somecases like these it requires just playing with the various commands to get it to work.

Neal Matthews
7th April 2010, 16:35
Cheers Mark I'll have a good fiddle with the code and see if I can get it to behave itself.

I don't think I'm far away now earlier this morning I was writing records to tdpur045 but I lost track of which version did this.

Hope to post back soon with the working version.

Cheers
Neal

Neal Matthews
8th April 2010, 15:01
Hello Mark,

Good news my code is now behaving. The find seemed to open up the sub session and once I'd got the tdpsc910 variables it was just a matter of then getting and putting the tdpur045 vars back in the main session before an update.

I just then had to add a section to deal with non valid items not seen in the sub session.

Thanks for all your help.

Cheers
Neal


function receipt()
{
do.update=true
m_error2=""
| Start creating a receipt
stpapi.put.field("tdpur4120m000", "tdpur045.reno", "4")

|* Handle question tdpur41206 yes
ret=stpapi.enum.answer( "tdpur4120m000", "tdpur41206", tcyesno.yes )

stpapi.put.field("tdpur4120m000", "form.dino", tdpsc966.pack)
stpapi.put.field("tdpur4120m000", "tdpur045.suno", tdpsc966.suno)

|* Handle question tdpur41207 no
ret=stpapi.enum.answer( "tdpur4120m000", "tdpur41207", tcyesno.no )

|* Activate sub process
stpapi.handle.subproc("tdpur4120m000", "tdpsc0191s000", "add")
ret = stpapi.change.view("tdpur4120m000",m_error2)
if m_error2 <> "" then
do.update = false
endif

stpapi.put.field("tdpsc0191s000", "tdpsc910.item", tdpsc966.item)
ret = stpapi.find("tdpsc0191s000",m_error2)
if m_error2 <> "" then
do.update = false
endif

stpapi.put.field("tdpsc0191s000", "tdpsc910.mark", str$(1))
stpapi.get.field( "tdpsc0191s000", "tdpsc910.item", m_item )

|* Check tdosc966 item found
if strip$(m_item) <> strip$(tdpsc966.item) then
stpapi.end.session("tdpsc0191s000")
stpapi.end.session("tdpur4120m000")
m_error2 = "NO SCHEDULE FOR ITEM"
else
ret=( stpapi.update( "tdpsc0191s000", do.update, m_error2 ) )
stpapi.continue.process("tdpsc0191s000",m_error2)
stpapi.end.session("tdpsc0191s000")

if strip$(m_error2) = "" then
stpapi.get.field( "tdpur4120m000", "tdpur045.orno", m_orno )
stpapi.get.field( "tdpur4120m000", "tdpur045.pono", m_pono )
stpapi.get.field( "tdpur4120m000", "tdpur045.item", m_item )

|message("orno " & m_orno)
|message("pono " & m_pono)
|message("item " & m_item)
|message(str$(tdpsc966.qty1))

stpapi.put.field("tdpur4120m000", "tdpur045.orno", strip$(m_orno))
stpapi.put.field("tdpur4120m000", "tdpur045.pono", strip$(m_pono))
stpapi.put.field("tdpur4120m000", "tdpur045.item", strip$(m_item))
stpapi.put.field("tdpur4120m000", "tdpur045.diqu", str$(tdpsc966.qty1))
stpapi.put.field("tdpur4120m000", "tdpur045.dqua", str$(tdpsc966.qty1))

ret=( stpapi.update( "tdpur4120m000", do.update, m_error2 ) )
endif
stpapi.end.session("tdpur4120m000")
endif
}