Baanboard.com

Go Back   Baanboard.com > Forum > Baan SIGs > AFS/DDC/OLE: Function servers

User login

Frontpage Sponsor

Main

Poll
How big is your Baan-DB (just Data AND Indexes)
0 - 200 GB
18%
200 - 500 GB
29%
500 - 800 GB
3%
800 - 1200 GB
8%
1200 - 1500 GB
8%
1500 - 2000 GB
11%
> 2000 GB
24%
Total votes: 79

Baanboard at LinkedIn


Reference Content

Reply
 
Thread Tools Display Modes
  #1  
Old 9th May 2019, 16:09
andy2609 andy2609 is offline
Member
 
Join Date: Feb 2011
Posts: 42
andy2609 is on a distinguished road
Baan: IVc4 - DB: Informix - OS: HP-UX
Cool Invoke 'start.set' via API Command

When calling a session with a type 3 form (tipcf1101m000 - Product Features by Generic Item), I need to add a new record for a Generic Item that initially has no records (in table tipcf100), using an API command.

Using 'stpapi.put.field' to put the relevant values, followed by either 'stpapi.find' or 'stpapi.change.view', the process simply finds the next record in the table. Hence, when using 'stpapi.insert', an error of 'Record already exists' is encountered. This is because the API is still focused on the Generic Item that already exists.

Therefore, what I need to do is execute a 'start.set' command via the API and to enter the new Generic Item - or I need to find another method of adding a record for a new Generic Item.

Any ideas as to a solution?
Reply With Quote
Sponsored Links
  #2  
Old 10th May 2019, 14:50
mark_h's Avatar
mark_h mark_h is offline
Guru
 
Join Date: Sep 2001
Location: Kentucky, USA
Posts: 7,384
mark_h will become famous soon enough
Baan: Baan 4C4 A&D1 - DB: Oracle - OS: Sun Solaris
Are you putting all of the fields including the set fields?

Couple of samples I know that work in theory I do not even need to do a change view. I should just be able to do a flat out insert with no find since I do not care if it already exists.
Code:
function add.builditem()
{
	stpapi.put.field( "tipgc8100m00b", "tipgc800.cprj", project )
	e = stpapi.change.view( "tipgc8100m00b" )
	stpapi.put.field( "tipgc8100m00b", "tipgc800.cprj", project )
	stpapi.put.field( "tipgc8100m00b", "tipgc800.butm", builditem )
	stpapi.put.field( "tipgc8100m00b", "tipgc800.dsca", "Simulation" )	| 20160113 
	stpapi.insert( "tipgc8100m00b", 1, errmsg)
|021902 Skip records already exist.  This means the build item
| was already added.
	if(strip$(errmsg)<>"" and pos(errmsg,"Record already exists")=0) then
		mess.1= "1." & builditem & " " & errmsg
		write.error(mess.1)
	else
		mess.1="1. Build item added. " & builditem
	endif
	display("mess.1")
	stpapi.end.session( "tipgc8100m00b" )
}
function add.subitem()
{
	stpapi.put.field( "tipgc8105m00b", "tipgc805.cprj", project )
	stpapi.put.field( "tipgc8105m00b", "tipgc805.butm", builditem )
	e = stpapi.change.view( "tipgc8105m00b" )
	stpapi.put.field( "tipgc8105m00b", "tipgc805.cprj", project )
	stpapi.put.field( "tipgc8105m00b", "tipgc805.butm", builditem )
	stpapi.put.field( "tipgc8105m00b", "tipgc805.sbtm", subitem )
	stpapi.put.field( "tipgc8105m00b", "tipgc805.dsca", "Simulation" )	| 20160113 
	stpapi.insert( "tipgc8105m00b", 1, errmsg )

|021902 Skip records already exist.  This means the sub item
| was already added.
	if(strip$(errmsg)<>"" and pos(errmsg,"Record already exists")=0) then
		mess.2= "2. "&subitem&" "&errmsg
		write.error(mess.2)
	else
		mess.2="2. Sub item added. " & subitem
	endif
	display("mess.2")
	stpapi.end.session( "tipgc8105m00b" )
}
__________________
Mark

GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.

Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #3  
Old 20th May 2019, 19:25
andy2609 andy2609 is offline
Member
 
Join Date: Feb 2011
Posts: 42
andy2609 is on a distinguished road
Baan: IVc4 - DB: Informix - OS: HP-UX
Primary Index fields are being put first

Thanks for your reply, Mark.

The primary index fields are being put before the 'stpapi.insert' command. I had thought the same as you - that it would not matter whether an existing record already exists for the Generic Item or not.

Here is a snippet of my code:
stpapi.put.field("tipcf1101m000", "tipcf100.item", strip$(i.gitm))
stpapi.put.field("tipcf1101m000", "tipcf100.sern", str$(i.sern))
ret = stpapi.change.view("tipcf1101m000", fs.error)

stpapi.put.field("tipcf1101m000", "tipcf100.item", strip$(i.gitm))
stpapi.put.field("tipcf1101m000", "tipcf100.sern", str$(i.sern))
stpapi.put.field("tipcf1101m000", "tipcf100.cpft", i.cpft)
stpapi.put.field("tipcf1101m000", "tipcf100.dsca", strip$(i.cpft.dsca))
stpapi.put.field("tipcf1101m000", "tipcf100.indt", str$(i.cpft.indt))
stpapi.put.field("tipcf1101m000", "tipcf100.exdt", str$(i.cpft.exdt))
stpapi.put.field("tipcf1101m000", "tipcf100.cnsc", i.cnsc)
stpapi.put.field("tipcf1101m000", "tipcf100.sopt", str$(fs.yes))
|
do.update = 1
lret = stpapi.insert("tipcf1101m000", do.update, fs.error)
|
lret = stpapi.save("tipcf1101m000", fs.error)


A 'Record already exists' error is returned by the function server.
Reply With Quote
  #4  
Old 20th May 2019, 21:27
mark_h's Avatar
mark_h mark_h is offline
Guru
 
Join Date: Sep 2001
Location: Kentucky, USA
Posts: 7,384
mark_h will become famous soon enough
Baan: Baan 4C4 A&D1 - DB: Oracle - OS: Sun Solaris
My system has 2 unique indices on the table. tipcf100.item and tipcf100.sern is the primary index on the form. Then there is tipcf100.item and tipcf100.cpft - also unique. Are you 100% sure the information you are putting to the form for those fields are unique?

Addition to post: On my system I would only put the item and do a change view. That is what is the primary field on the form. The sern would be a variable. I would always want it to be max+1 for the generic item in question.
__________________
Mark

GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.

Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #5  
Old 21st May 2019, 19:00
andy2609 andy2609 is offline
Member
 
Join Date: Feb 2011
Posts: 42
andy2609 is on a distinguished road
Baan: IVc4 - DB: Informix - OS: HP-UX
Function Server variable values reflect session user defaults

Hi again Mark. Thanks for your thoughts on this.

The table on the system I am working on also has the same index values as yours and yes, the data is unique.

On my system, when putting the item and executing a 'change view', the Generic Item value in User Defaults for the session (for instance, when the session was last closed) is always retrieved.

This is borne out by the following command returning the default item to the variable 'view.gitm':
stpapi.get.field("tipcf1101m000", "tipcf100.item", view.gitm)

I have worked around this by ensuring that the first instance of inserting a Product Feature by Generic Item is added with db.insert - thereafter, the function server process works fine.

Thanks again for your input!
Reply With Quote
  #6  
Old 22nd May 2019, 15:00
mark_h's Avatar
mark_h mark_h is offline
Guru
 
Join Date: Sep 2001
Location: Kentucky, USA
Posts: 7,384
mark_h will become famous soon enough
Baan: Baan 4C4 A&D1 - DB: Oracle - OS: Sun Solaris
That is interesting and a good work around. I am glad I did not have that issue with the ones I did. I had to use an actual update in a few cases where fields would not update the the api code - but never a key index field. I think one of them was like the terms of pmt or delivery on the purchase order header - never could get it to update, so just did a select/find/db.update.
__________________
Mark

GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.

Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #7  
Old 23rd May 2019, 12:34
andy2609 andy2609 is offline
Member
 
Join Date: Feb 2011
Posts: 42
andy2609 is on a distinguished road
Baan: IVc4 - DB: Informix - OS: HP-UX
Thanks!

Thanks for taking the time to think about and respond to this Mark. Appreciated!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Call Standard Form Command from User Form Command with Extension lakoon Tools Administration & Installation 4 22nd February 2019 08:25
Programming Question mr_suleyman Tools Development 37 11th November 2016 09:14
change Form Command Availability at run time aamir_faried Tools Development 7 5th January 2015 21:59
Handling Unit functionality baazigar Distribution, Transportation & Warehousing 4 19th February 2012 16:54
How to make API if you have more purchase orders for one supplier and item? confused AFS/DDC/OLE: Function servers 3 18th February 2010 17:47


All times are GMT +2. The time now is 12:56.


©2001-2018 - Baanboard.com - Baanforums.com