tracylee
16th July 2018, 04:23
HI,

I have a problem when using AFS to insert data into tibom1110m000. Until script bom_ret4, it cannot be save it. Prompt message bom_ret4 = 1. Please advise.


function exec.bom()
{
long bom_ret1, bom_ret2, bom_ret3, bom_ret4
string find.msg(100), error.msg(100), syn.msg(100), recover.msg(100), sav.msg(100)

stpapi.put.field("tibom1110m000", "tibom010.mitm", str$(item_with_project_name))

bom_ret1 = stpapi.find("tibom1110m000", find.msg)

if bom_ret1 = 1 then
message("BOM Item Code already Exist!")
message("Item created Failed!")
else
bom_ret2 = stpapi.synchronize.dialog("tibom1110m000", "add", syn.msg)

if bom_ret2 then

stpapi.put.field("tibom1110m000", "tibom010.mitm", str$(item_with_project_name))
stpapi.put.field("tibom1110m000", "tibom010.pono", str$(10))
stpapi.put.field("tibom1110m000", "tibom010.seqn", str$(1))
stpapi.put.field("tibom1110m000", "tibom010.sitm", str$(full.bom.item))
stpapi.put.field("tibom1110m000", "tibom010.qana", str$(bom.qty))
stpapi.put.field("tibom1110m000", "tibom010.cwar", "FINFB")
stpapi.put.field("tibom1110m000", "tcibd001.cuni", "pcs")
stpapi.put.field("tibom1110m000", "tibom010.opno", str$(10))

bom_ret3 = stpapi.insert("tibom1110m000", 0, error.msg)
message("bom_ret3: %s",bom_ret3)
bom_ret4 = stpapi.save("tibom1110m000", sav.msg)
message("bom_ret4: %s",bom_ret4)
if not bom_ret3 or not bom_ret4 then
stpapi.recover("tibom1110m000", recover.msg)
message("BOM Item created Failed!")
else
create.stat = "Succeed"
endif
stpapi.end.session("tibom1110m000")
endif
endif

stpapi.end.session("tibom1110m000")
}

tmannais
16th July 2018, 06:26
Can you try to message these two variables after the save() to see if they contain any error messages?
- error.msg
- sav.msg

tracylee
16th July 2018, 07:41
Can you try to message these two variables after the save() to see if they contain any error messages?
- error.msg
- sav.msg

Hi,

I get the error.msg :
Change the value of the Sequence Number field.
Reason:BOM Line PCS-F-E 100-BHH-710,10,1 is already present.

save.msg: is empty

Why the BOM Line get different item code?
Because my main item code is FC-F-C 200-BH-1300, BOM item code is FC-F-C G6488-634.

I got try to message the "item_with_project_name" and "full.bom.item", it is correct item code for main item code and BOM Item code. Please advise. Thanks.

tmannais
16th July 2018, 08:01
That is strange. Maybe you just didn't put.field() into the correct field name. You should check all of the field names again.
However, for case like this I recommend using DAL. It is easier and is more likely to get the job done than AFS.
Here is an example for inserting a record.

| ******************** DAL **********************
if dal.new.object(TABLE_NAME) <> 0 then
dal.get.error.message(error.msg)
return(error.msg)
endif
dal.set.field(FIELD_NAME, VALUE)
. . . (you can set multiple fields here)
if dal.save.object(TABLE_NAME) <> 0 then
dal.get.error.message(error.msg)
endif
| ***********************************************

And of course, don't forget to include this line at the top of the file.
#include <bic_dam> |* Mandatory for using DAL

tracylee
16th July 2018, 12:34
That is strange. Maybe you just didn't put.field() into the correct field name. You should check all of the field names again.
However, for case like this I recommend using DAL. It is easier and is more likely to get the job done than AFS.
Here is an example for inserting a record.

| ******************** DAL **********************
if dal.new.object(TABLE_NAME) <> 0 then
dal.get.error.message(error.msg)
return(error.msg)
endif
dal.set.field(FIELD_NAME, VALUE)
. . . (you can set multiple fields here)
if dal.save.object(TABLE_NAME) <> 0 then
dal.get.error.message(error.msg)
endif
| ***********************************************

And of course, don't forget to include this line at the top of the file.
#include <bic_dam> |* Mandatory for using DAL

Hi,

Thanks for your advice. Now work well. Thanks a lot. ^^