PW@KKI
22nd September 2013, 20:40
Reet then, after many weeks of code, test, code, test, I finally got a working solution that uses a web page to use function servers and create a Sales Quotation in Infor LN.

Here is my basic code:


BaanObj = CreateObject("Baan.Application.default")
BaanObj.Timeout = 60

On Error GoTo BaanAutomationError
'SET FIELDS IN SESSION
Dim type As Type = sqd.[GetType]()
Dim properties As PropertyInfo() = type.GetProperties()

ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & "tdsls1600m000" & Chr(34) & "," & Chr(34) & "tdsls100.qono" & Chr(34) & "," & Chr(34) & Trim("CHK") & Chr(34) & ")")
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & "tdsls1600m000" & Chr(34) & "," & Chr(34) & "tdsls100.ofbp" & Chr(34) & "," & Chr(34) & Trim("CUSKEN017") & Chr(34) & ")")
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & "tdsls1600m000" & Chr(34) & "," & Chr(34) & "tdsls100.sotp" & Chr(34) & "," & Chr(34) & Trim("CTL") & Chr(34) & ")")
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & "tdsls1600m000" & Chr(34) & "," & Chr(34) & "tdsls100.cofc" & Chr(34) & "," & Chr(34) & Trim("AFT") & Chr(34) & ")")

'INSERT RECORD
BaanObj.ParseExecFunction("ottstpapihand", "stpapi.insert(" & Chr(34) & sSession & Chr(34) & ",1," & Chr(34) & sErrMsg & Chr(34) & ")")
If BaanObj.Error <> 0 Or BaanObj.ReturnValue <> "1" Then
Label1.Text = "Error on inserting data:" & vbNewLine & _
"return value = " & ret.ToString() & vbNewLine & _
"BaanObj.Error = " & BaanObj.Error & vbNewLine & _
"BaanObj.ReturnValue = " & BaanObj.ReturnValue & vbNewLine & _
"BaanObj.ReturnCall = " & BaanObj.ReturnCall
Else
BaanObj.ParseExecFunction("ottstpapihand", "stpapi.get.field(" & Chr(34) & _
sSession & Chr(34) & "," & Chr(34) & "tdsls100.qono" & _
Chr(34) & "," & Chr(34) & getfield & Chr(34) & ")")
retCall = BaanObj.ReturnCall
retArea = Mid(retCall, 51, Len(retCall) - 51 - 1)
Label1.Text = "Quote " & retArea & " created successfully!!"
End If


Now, I have trimmed this down a bit , but it works!


I beleive that there are parts of the quotation creation routine that use another session - for example the field Internal Sales Rep is part of session tdsls1500m000 (as modify).

My issue is how to populate data in another session during the quotation creation session.

I have tried additional code:


ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.synchronize.dialog(" & Chr(34) & "tdsls1500m000" & Chr(34) & "," & Chr(34) & "add" & Chr(34) & "," & Chr(34) & sErrMsg & Chr(34) & ")")
ret = BaanObj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & "tdsls1500m000" & Chr(34) & _
"," & Chr(34) & "tdsls100.crep" & Chr(34) & _
"," & Chr(34) & Trim("1689") & Chr(34) & ")")


Yet again, everything successfully runs through and a quote is created, but the field in the 2nd session is not updated.


I'm obviously doing something wrong, but I have no idea what ....... HELP !!!!!


Thanks,
Paul

mark_h
23rd September 2013, 01:10
If you are using baan 4 then I would expect a stpapi.handle.subproc before the sub-session(or next session) is called. So for example if you put fields on session1, then do an insert and session 2 is launched for more information. Then before I did the insert I would have stpapi.handle.subproc. This would allow the function server to control the next session. Then I would put the data on the next session and insert (or update whatever action is needed). Then I would end the subsession and end the main session.

Below is a sample - we do not use the session you mentioned.

function extern insert_outbound( domain tcmcs.str12 runnumber,
domain tdilc.kooa order.type,
domain tcorno order.number,
domain tcpono order.position,
domain tdilc.loca order.location,
domain tccuni order.stun,
domain tcqiv1 order.qty,
domain tdltc.clot order.lot,
domain tcdate order.date,
ref string strsera(),
ref string strserb(),
ref string msg())
{
msg = ""
stpapi.handle.subproc("tdilc4101m000","tdilc4102s000","add")
stpapi.put.field("tdilc4101m000","runnumber",runnumber)
stpapi.put.field("tdilc4101m000","k.o.order",str$(order.type))
stpapi.put.field("tdilc4101m000","ordernr",str$(order.number))
stpapi.continue.process("tdilc4101m000",msg)
if not isspace(msg) then
stpapi.end.session("tdilc4101m000")
return
endif
stpapi.enum.answer("tdilc4102s000","tdilc4102.1",tcyesno.no)
stpapi.put.field("tdilc4102s000","tdilc401.pono",str$(order.position))
stpapi.put.field("tdilc4102s000","tdilc401.loca",order.location)
| 092404.st - Add lot and date to insert outbound.
stpapi.put.field("tdilc4102s000","tdilc401.clot",order.lot)
stpapi.put.field("tdilc4102s000","tdilc401.date",str$(order.date))
| 092404.end
stpapi.put.field("tdilc4102s000","tdilc401.stun",order.stun)
stpapi.put.field("tdilc4102s000","tdilc401.qstr",str$(order.qty))
rc = stpapi.insert("tdilc4102s000",1,msg)
if isspace(msg) then
stpapi.get.field( "tdilc4102s000", "tdilc401.sera", strsera )
stpapi.get.field( "tdilc4102s000", "tdilc401.serb", strserb )
endif
stpapi.end.session("tdilc4513s000")
stpapi.end.session("tdilc4102s000")
stpapi.end.session("tdilc4101m000")
}

PW@KKI
23rd September 2013, 17:26
Thank for the reply, Mark. However, I'm still not getting the result I want!!!!!

Now (not forgetting I am coding this in visual basic and calling it from outside of LN), the first part (creating the quote header) works fine - I get a new quote number and everything is rosey!

I have even tried to 'amend' the quote using the other session number - but that doesn't work either - probably because my code syntax is incorrect (see below) ...


BaanObj.ParseExecFunction(dllname, "stpapi.put.field(""tdsls1500m000"", ""tdsls100.qono"", ""CTL000017"")")
BaanObj.ParseExecFunction("ottstpapihand", "stpapi.find(""tdsls1500m000"",1," & Chr(34) & sErrMsg & Chr(34) & ")")
BaanObj.ParseExecFunction(dllname, "stpapi.put.field(""tdsls1500m000"", ""tdsls100.crep"", ""1689"")")
BaanObj.ParseExecFunction("ottstpapihand", "stpapi.update(""tdsls1500m000"",1," & Chr(34) & sErrMsg & Chr(34) & ")")


Do you have any other ideas?

Cheers

mark_h
23rd September 2013, 18:40
Since this is LN I can't really help - I don't know the sessions and since it is LN it could be the stpapi.sync.dialog like you first posted. About the only thing I can recommend is if you have source code you can try and debug it to see what happens.

bhushanchanda
23rd September 2013, 19:11
Hi,

As Mark said, you should use ret = stpapi.synchronize.dialog("tdsls1500m000", "Modify", error)

Generally, you need to chage the "Modify" keyword based on the session. First you create a new sales quotation you enter the details in the front view. Now, you go to header details to enter the Internal Sales Rep. Now, in the bottom right you can see if its Modify or add or Add. I checked it and its Modify. So, you can try the command :-

ret = stpapi.synchronize.dialog("tdsls1500m000", "Modify", error)

You can see this Thread (http://www.baanboard.com/baanboard/showthread.php?t=64487) where I have given an example of inserting Item Routing.

Well, again, if you just want to create a Sales Quotation, you can use a DLL too. Now, just call the DLL with the required parameters and then you can either use DAL or AFS to create the Sales Quotation.

Check this Thread (http://www.baanboard.com/baanboard/showthread.php?t=64202)

I hope you remember ;)

PW@KKI
24th September 2013, 12:31
Thanks for the input guys, but I still have a problem ..... I do believe it's the actual "stpapi.update" statement:

ret = BaanObj.ParseExecFunction(dllname, "stpapi.update(""tdsls1500m000"",1," & Chr(34) & sErrMsg & Chr(34) & ")")


Everything works fine - put, find, get field, synchronize dialog ..... but the update .... well, I don't get any errors and my program claims that everything has worked .... arrrggghhhhhhhhh

:confused:

mark_h
24th September 2013, 14:19
Well if you have source code you can put that session in debug mode to see what happens when you send the update. Another thing from the documentation on the stpapi.synchronize.dialog - I notice they put fields on the subsession, but the actual update command is on the main session. See sample below.


stpapi.put.field("dtfsa1501m000", "dtfsa101.seno", str$(i.seno))
ret = stpapi.find("dtfsa1501m000", error.msg)
if ret then
ret = stpapi.synchronize.dialog("dtfsa1501m000", "modify", error.msg)
if ret then
stpapi.put.field("dtfsa1101s000", "dtfsa101.name", new.name)
ret = stpapi.update("dtfsa1501m000", true, error.msg)
endif
endif