tmannais
30th March 2018, 11:27
Hi,

I am working on an AFS program that tries to simulate user interaction in the Outbound Advice session (whinh4525m000) in order to create a new record.
Here is the code:

session.code = "whinh4525m000" | Outbound Advice Session
stpapi.clear(session.code)
if stpapi.synchronize.dialog(session.code, "add", error.msg) then
stpapi.put.field(session.code, "whinh225.oorg", "1")
stpapi.put.field(session.code, "whinh225.orno.segment.1", "BOX000111")
stpapi.put.field(session.code, "whinh225.oset", "1")
stpapi.put.field(session.code, "whinh225.pono", "1")
stpapi.put.field(session.code, "whinh225.seqn", "0")
stpapi.put.field(session.code, "whinh225.sern", "1")
stpapi.put.field(session.code, "whinh225.qads", "3")
stpapi.get.field(session.code, "whinh225.runn", output)
ret = stpapi.insert(session.code, true, error.msg)
if (not isspace(error.msg)) then
message("Cannot Insert : " & error.msg)
endif
else
error.msg = "Cannot open synchronized dialog: " & error.msg
endif
stpapi.end.session(session.code, error.msg)

However, there is an error message at the end saying "Enter a value for the Business Object Type field.", but the field is actually not mandatory.
In addition, I tried manually putting those fields (without Business Object Type field) and the record is created just fine.
Please advice.

Regards,
Thana

mark_h
30th March 2018, 19:35
Searching for code on the site - I say one post that has orno not as a segment. So I can't answer that. I will say calling code via api code it does not always work like it does manually. In this case it might not be setting something that makes it skip checking the field. Sometimes you can do a insert without true and then do a save. I have had to do some different things like that to get API code to work in 4c4. Can't really help with LN.

tmannais
2nd April 2018, 04:32
I have tried using orno not as a segment, and I have also tried insert with false then save, but no luck.
orno way gives me the same error while inserting with false then save gives me the same error on insert but not on save.
So, none of these seem to work.

mark_h
2nd April 2018, 14:38
You wouldn't by chance happen to have code so you could debug what is happening would you?

giggty
2nd April 2018, 16:18
orno is definitely not a segmented field. When you are creating new record by hand, do you fill only those fields you have in your code? Does it throw any messages at you during it? Try to get all messages generated in session:

ret = stpapi.insert(session.code, true, error.msg)
if not ret then
while true
error.code = stpapi.get.mess.code(session.code, error.msg)
if isspace(error.msg) then
break
endif
message(error.msg)
endwhile
stpapi.recover(session.code, recover.msg)
endif

I encountered a weird error in AFS once, turned out it was another field all the time having been filled incorrectly rather then the one error message pointed to.

tmannais
3rd April 2018, 05:09
mark_h, I tried debugging the AFS.
Here's the result:

LOGGING STARTED
03-04-2018
>whinh4525m000 clear
45dll->serv (getxml)
45dll->serv (startwhinh4525m000100)
47serv<-4gl (api.child.startedwhinh4525m00045)
47serv<-4gl (init.ready)
whinh4525m000(47)-RUNNING:
45dll->serv (startwhinh4525m0001whinh4525m000114)
49serv<-4gl (init.ready)
whinh4525m000(49)-RUNNING:
45dll->serv (syncadd47)
whinh4525m000(47)-RUNNING:syncadd
47serv<-4gl (syncadd0)
whinh4525m000(47)-RUNNING:
>whinh4525m000(47) put.field:whinh225.oorg 1
>whinh4525m000(47) put.field:whinh225.orno BOX000111
>whinh4525m000(47) put.field:whinh225.oset 1
>whinh4525m000(47) put.field:whinh225.pono 1
>whinh4525m000(47) put.field:whinh225.seqn 0
>whinh4525m000(47) put.field:whinh225.sern 1
>whinh4525m000 get.field:whinh225.oorg
<whinh4525m000(49) get.field:whinh225.oorg=1
>whinh4525m000 get.field:whinh225.orno
<whinh4525m000(49) get.field:whinh225.orno=BOX000111
>whinh4525m000 get.field:whinh225.pono
<whinh4525m000(49) get.field:whinh225.pono=1
>whinh4525m000 get.field:whinh225.seqn
<whinh4525m000(49) get.field:whinh225.seqn=0
>whinh4525m000 get.field:whinh225.sern
<whinh4525m000(49) get.field:whinh225.sern=1
>whinh4525m000 get.field:whinh225.oset
<whinh4525m000(49) get.field:whinh225.oset=1
>whinh4525m000(47) put.field:whinh225.qads 3
>whinh4525m000 get.field:whinh225.runn
<whinh4525m000(49) get.field:whinh225.runn=
>whinh4525m000 insert
45dll->serv (add.set+save49)
whinh4525m000(49)-RUNNING:add.set+save
49serv<-4gl (add.set+save10)
whinh4525m000(49)-RUNNING:
<whinh4525m000 Enter a value for the Business Object Type field.
>whinh4525m000 get.mess.code
<whinh4525m000
>whinh4525m000 get.field:whinh225.oorg
<whinh4525m000(49) get.field:whinh225.oorg=1
>whinh4525m000 get.field:whinh225.orno
<whinh4525m000(49) get.field:whinh225.orno=BOX000002
>whinh4525m000 get.field:whinh225.pono
<whinh4525m000(49) get.field:whinh225.pono=10
>whinh4525m000 get.field:whinh225.seqn
<whinh4525m000(49) get.field:whinh225.seqn=0
>whinh4525m000 get.field:whinh225.sern
<whinh4525m000(49) get.field:whinh225.sern=2
>whinh4525m000 get.field:whinh225.oset
<whinh4525m000(49) get.field:whinh225.oset=1
>whinh4525m000 end.session
45dll->serv (end.program47)
whinh4525m000(47)-RUNNING:end.program
whinh4525m000(49)-RUNNING:end.program
47serv<-4gl (end.program0)
whinh4525m000(47)-RUNNING:
47dll->serv (whinh4525m000: exit(47))
49dll->serv (whinh4525m000: exit(49))

It looks like I put the fields correctly but it still asks for Business Object Type field.
And giggty, I also tried your code but it displays no error messages.

mark_h
3rd April 2018, 14:55
I was hoping you had baan source code you could debug and step thru to see what is happening. My suspicion is that when you run it manually and move thru the fields and event gets hit which says that business object type field is not needed, but when you run it via AFS code it does not hit that event. Is it possible to put that field and then maybe go back and edit it to make it empty?

tmannais
4th April 2018, 04:37
I don't have the source code.
I have tried putting the Business Object Type field but it then asked for another non-mandatory field, and when I put in the field it gave me another error. So, I think it is not the way it should be because I have to put so many non-mandatory fields that are not even required. Most of them will be left blank by the users when manually create as well.
However, yesterday I gave DAL a try and it seems to do the work just fine. So, I want to ask what are the things I should keep in mind when I try to use DAL instead of AFS for the same work.

giggty
4th April 2018, 16:21
I tried to create an Advice through AFS filling in exactly the same fields and values I use when doing it manually and it throws an error regarding some irrelevant existing line :confused: I could not figure it out.
So if DAL approach worked for you then just go for it. Nothing special to keep in mind here, DAL does the heavy lifting ;)

tmannais
5th April 2018, 04:44
Thank you mark_h and giggty for the advice. I finally use the DAL instead of AFS to solve this problem. It works like a charm and it is way eaiser than I thought. Here's the code for anyone who is having the same problem as I was.

*only the DAL part*

if dal.new.object("whinh225") <> 0 then
dal.get.error.message(error.msg)
return(error.msg)
endif
dal.set.field("whinh225.oorg", i.tdcrm411.oorg)
dal.set.field("whinh225.orno", str$(i.tdcrm411.orno))
dal.set.field("whinh225.oset", i.tdcrm411.oset)
dal.set.field("whinh225.pono", i.tdcrm411.pono)
dal.set.field("whinh225.seqn", i.tdcrm411.seqn)
dal.set.field("whinh225.sern", i.tdcrm411.sern)
dal.set.field("whinh225.locf", str$(i.tdcrm411.loca))
dal.set.field("whinh225.clot", str$(i.tdcrm411.clot))
dal.set.field("whinh225.qads", i.tdcrm411.qads)
dal.set.field("whinh225.idat", i.tdcrm411.idat)
if dal.save.object("whinh225") <> 0 then
dal.get.error.message(error.msg)
return(error.msg)
endif
if get.var(pid,"whinh225.runn", o.tdcrm411.runn) <> 1 then
error.msg = "Cannot get Run Number."
endif
return(error.msg)