Troy M
20th February 2006, 17:08
I need to use the APIs to create new records in "Business Partners by Project" (tppdm6501m000).

Problem: when clicking on the "New" button in tppdm6501m000, the sub-session that opens up (tppdm6101s000) reads the project code from the main session and doesn't allow the user to browse for it.

Therefore, I need to pre-set the project code in tppdm6501m000 before opening session tppdm6101s000.

To do this, I assume I'll need to

1. create a "New Group" in tppdm6501m000
2. set the project code with:

stpapi.put.field( "tppdm6501m000", "tppdm740.cprj", cprj )

3. sync the sub-session:

returnVal = stpapi.synchronize.dialog("tppdm6501m000", "add", error)

4. then add the values to the sub-session and save:

stpapi.put.field( "tppdm6101s000", "tppdm740.ofbp", ofbp )
stpapi.put.field( "tppdm6101s000", "tppdm740.ccur", ccur )
...
returnVal = stpapi.insert( "tppdm6101s000", do.update, error)
...
returnVal = stpapi.save( "tppdm6100s000", error )

Steps 2, 3 and 4 work fine when adding records to a project that already has records in the session.

Can anyone help me with step 1 please? How do you use the APIs to call standard commands?

mark_h
21st February 2006, 16:29
Well since this is Baan V I can't be to sure about the answer. But typically when I create a new group I do a stpapi.change.view. Depending on the session on what may happen. Since this is Baan V I do not know anything about sync'ing up the dialog.

Troy M
23rd February 2006, 12:13
Hi Mark,

Thanks very much for the help - the stpapi.change.view call works. Here's the working code:



error = ""

stpapi.put.field( "tppdm6501m000", "tppdm740.cprj", cprj )
returnVal = stpapi.change.view( "tppdm6501m000" , error )

if error="" then

returnVal = stpapi.synchronize.dialog("tppdm6501m000", "add", error)

if error="" then

stpapi.put.field( "tppdm6101s000", "tppdm740.cprj", cprj )
stpapi.put.field( "tppdm6101s000", "tppdm740.ofbp", ofbp )
stpapi.put.field( "tppdm6101s000", "tppdm740.ccur", ccur )
stpapi.put.field( "tppdm6101s000", "tppdm740.fcrt", str$(fcrt))
stpapi.put.field( "tppdm6101s000", "tppdm740.cinm", cinm)
stpapi.put.field( "tppdm6101s000", "tppdm740.ratf", str$(ratf) )
stpapi.put.field( "tppdm6101s000", "tppdm740.copr", str$(copr) )
stpapi.put.field( "tppdm6101s000", "tppdm740.cadr", cadr )
stpapi.put.field( "tppdm6101s000", "tppdm740.refe", refe )
stpapi.put.field( "tppdm6101s000", "tppdm740.cvat", cvat )

returnVal = stpapi.insert( "tppdm6101s000", do.update, error)

if error="" then

returnVal = stpapi.save( "tppdm6100s000", error )
success = 1
writeLog("Create business partner " & ofbp & " for project " & cprj & ".")
else
writeLog("Error with " & ofbp & " for project " & cprj & ": " & error)
endif

stpapi.end.session( "tppdm6101s000" )
else
writeLog("Unable to open sub-session to add business partner: " & error)
endif
else
writeLog("Unable to create new group for project: " & cprj & ": " & error)
endif


Troy