pradeepcr
13th June 2019, 17:54
Hello,
I am trying to call the main session tiitm0101m000 through AFS and then invoke the session tiitm0202s000 using the copy button on the tiitm0101m000 form. I tried stpapi.form.command() but does not work probably because this is Baan IV. Any ideas on how I can achieve this using AFS.

Thanks,
PC

OmeLuuk
14th June 2019, 01:34
I think you're on the right track, but probably with the wrong prerequisites?
Like did you search the record, marked it, perform the form command (if it fails, read the error stack, functional and technical) and tried the AFS_LOG option? What did it teach you?

pradeepcr
14th June 2019, 16:52
stpapi.form.command() is not work in Baan IV. Program script gives a compilation error. AFS guide also clearly says it is only supported in Baan ERP and Ln. It says alternative to that is continue.process() in Baan IV but there is no continue button on tiitm0101m000.

What I am trying to achive - from custom session I need to pass the item code and call maintain item data and from there invoke the copy button which opens tiitm0202s000 to copy the item. All this through AFS.

mark_h
17th June 2019, 04:14
When I get to work tomorrow I will look thru my code. I think I did something for this sub-session at one time.

mark_h
17th June 2019, 15:48
Well I can't find any code but in 4c4 you would use stpapi.application.option. I am waiting to get our test server backup. Maybe I only wrote test code. Every since we converted they seem to like to ignore our old baan servers. :)


SYNTAX
void stpapi.application.option(string session, long form, long option, ref string err.mesg)
ARGUMENTS
session Name of the session this command is executed on.
form Form number on which user option must be executed. User options (the commands on the Special menu) are defined per form.
option The option number to be executed. User options appear as choice.user.x options in the Baan 4GL code where x is a number that ranges from 0 to 9. The value of x that corresponds to the option that you want to activate is provided as the value of this parameter.
err.mesg This parameter will contain the text of the error message if the function cannot complete normally

pradeepcr
17th June 2019, 16:31
Thanks a lot for checking. stpapi.application.option can only be used for user defined options 0 to 9 in choice.user.o/9 section. It does not support the standard copy option 16(dupl.occur) in this case.

mark_h
17th June 2019, 22:45
Yep - you are correct. I see a bunch of zoom.to's on the session, but in production I am not seeing any stpapi code.

Have you tried just running the session directly. Maybe setting the tiitm001.item before calling the session. I know on the zoom.to we include copy.item = zoom.to$("tiitm0202s000",z.session,"tiitm001.item", "copy.item",0) where the copy.item is set to tiitm001.item. You might have to change the session type since it will might not let you activate a subsession.

Or another alternative is to create your own calling session. All it would have to do is set the original item and activate tiitm0202s000. I did that for another session - I had to do that so I could control the subsession that it launched automatically.

pradeepcr
18th June 2019, 23:20
Mark, I want that subsession to run automatically for a set of original items without manual intervention. I guess that is not possible with the solutions that you are suggesting.

mark_h
19th June 2019, 15:34
Not sure I get that. If you create a session to launch the tiitm0202m000 then no manual intervention would be needed. I can show you an example of one I did - so if you run tpptc9820m00c on our system it automatically runs tpptc9110m00c. I could never get control of the tpptc9110m00c session it ran. So I cheated. I created a new session called tpptc9831m000. This session has one input field x and all it does is launch the session I want to use tpptc9110m00c.

declaration:
long child.id
extern domain tcmcs.str1 x
|****************************** PROGRAM SECTION ***************************
before.program:
child.id = 0

|****************************** ZOOM FROM SECTION ***************************
|****************************** FORM SECTION ***************************
|****************************** CHOICE SECTION ***************************
choice.cont.process:
on.choice:
if(child.id<>0) then
kill(child.id)
endif
child.id=activate("tpptc9110m00c")
switch.to.process(child.id)
| Cannot use zoom because tpptc9110m00c is waiting for a
| switch.to.process
execute(end.program)

choice.interrupt:
before.choice:
execute(end.program)

choice.abort.program:
before.choice:
execute(end.program)

choice.end.program:
before.choice:
kill(child.id)


So what I am proposing is let say you create a session tiitm9999m000 - 1 input field the item. Then it does the zoom to as I mentioned above. It should all remain in the background. So what you would see if you looked at your process would be your copy session as the parent, then tiitm9999m000 as a child and then tiitm0202s000 as a child of tiitm9999m000. Then you should be able to put the new item and set the text flags. It does not hurt to give it a try. There should be no manual intervention.

And yes 2 days and I am still waiting on our test system to be started. Or maybe fix my user ID so I can putty into the servers.

pradeepcr
19th June 2019, 19:20
Thanks Mark.

"Then you should be able to put the new item and set the text flags." How can I pass these values from Activate(tiitm0202s000)?

pradeepcr
20th June 2019, 00:26
Mark,
This is what I tried. I created a new session with one field 'Item' on it and a 'Continue' button.

On choice.continue:
zoom.to$("tiitm0202s000",z.session,"tiitm001.item", "copy.item",0)

In the copy item range session I call the new session using AFS:

stpapi.put.field("awitm0230m003", "tiitm001.item", strip$(awitm030.item))
stpapi.handle.subproc("awitm0230m003", "tiitm0202s000", "add")
stpapi.zoom.option("awitm0230m003", 1, "tiitm0202s000", error.msg)
stpapi.put.field("tiitm0202s000", "copy.item", strip$(awitm030.part))
stpapi.put.field("tiitm0202s000", "copy.alt.items", str$(etol(tcyesno.no)))
stpapi.put.field("tiitm0202s000", "copy.alt.suppl", str$(etol(tcyesno.no)))
stpapi.put.field("tiitm0202s000", "copy.erela", str$(etol(tcyesno.no)))
stpapi.continue.process("tiitm0202s000", error.msg)
stpapi.end.session("tiitm0202s000")
stpapi.end.session("awitm0230m003")

error.msg on the continue process (in bold) says "Session not available".

Any idea?

mark_h
20th June 2019, 14:26
I would try stpapi.continue after these 2 lines like this:
stpapi.put.field("awitm0230m003", "tiitm001.item", strip$(awitm030.item))
stpapi.handle.subproc("awitm0230m003", "tiitm0202s000", "add")
stpapi.continue.process("awitm0230m003", error.msg)

Based on the where you put the zoom to in in the new session - it was in the continue on the new session:
On choice.continue:
zoom.to$("tiitm0202s000",z.session,"tiitm001.item", "copy.item",0)

pradeepcr
20th June 2019, 16:11
It works!!! You rock!!!

mark_h
20th June 2019, 17:12
Well I got the test system back today - finally. What I actually tested was adding it to the zoom menu. I new I had tried something once before. So if I ran tiitm0101m000 and did tools zoom I see copy item.

function copy_item()
{
long ret, count
stpapi.put.field("tppdm0110m000","tiitm001.item", "MYTEST91528")
ret = stpapi.find("tppdm0110m000")
stpapi.handle.subproc("tppdm0110m000", "tiitm0202s000", "add")
stpapi.handle.subproc("tppdm0110m000", "mtiitm000090011", "7")
stpapi.zoom.option("tppdm0110m000",1,"tiitm0202s000",err)
stpapi.put.field("tiitm0202s000", "copy.item", "mark345")
stpapi.enum.answer("tiitm0202s000", "tiitm0101t", tcyesno.yes)
stpapi.continue.process("tiitm0202s000",err)
|stpapi.insert("tppdm0110m000",1,err)
stpapi.end.session("tiitm0202s000")
if(ret <> 1) then
message("err")
endif
|stpapi.enum.answer("tppdm0110m000", "tiitm01012", tcyesno.yes)
|stpapi.delete("tppdm0110m000",1,err)
message(err)
stpapi.end.session("tppdm0110m000")

}


So another option if needed.

pradeepcr
21st June 2019, 16:34
Thanks for sharing the other option.