Neal Matthews
6th October 2011, 18:01
Hello all,
I have discovered an unusual problem with my Supply Chain Maintain Receipts AFS. Basically it is not 100% guaranteed to work with certain items as the put.field in the sub session does not always find the correct item.
I have discovered that my code is 100% OK if the tdpsc0191s000 session has it's Index key set to the default sort. However the user of the session prefers an alternative sort.
So the options are.
1) Can AFS be used to change the order when the session is started ?
2) Clone the session tdpsc0191s000. I have actually tried this but I get an error and as it's a sub session I can't run it's not easy to see what is going on.
Any ideas greatly appreciated.
Cheers Neal
stpapi.put.field("tdpsc0191s000", "tdpsc910.item", tdpsc971.item)
ret = stpapi.find("tdpsc0191s000",m_error1)
if m_error1 <> "" then
message("Find Error " & m_error1)
do.update = false
endif
stpapi.put.field("tdpsc0191s000", "tdpsc910.mark", str$(1))
stpapi.get.field( "tdpsc0191s000", "tdpsc910.item", m_item )
mark_h
6th October 2011, 21:06
(1) My first thought was clone the session - not the scripts, forms or reports. Those can stay the same. On the new session, just remove the order by option. Set the default to the option you need and use it instead of the real session. You would have to give users access to the session, but you do not have to put it on the menu or in the dem flow. One way to avoid this issue.
(2) My second thought was if they change the order by what does the find button fields look like. I am thinking you could use the field you have item(assuming it is the key primary index field) - do a select on the database to find the item first. Then put ALL the field you need for a find no matter which index is in use. In theory the find should work at this point. I do not have a test system to try something like this on. Not sure if this is making sense to you or not.
mark_h
6th October 2011, 21:24
Found an example for #2 above. So lets say my API program is going to update the item master. I will always be fed the item to run the update. Now one of my purchasing customers who will use the update like the item master sorted by search key 1 - which is index two. What I could do in the program is take the item, do a select with it, get item and search key 1, put both fields on the form, then do the find. Then no matter which index 1 or index 2 the customer has saved it should work. I could do the same for the other indexes on the item master also, but just picked the first two as an example.
Neal Matthews
7th October 2011, 12:36
Cheers Mark you're a lifesaver got it going now.
I did a select on tdpsc910 and then put field tdpsc910.ddtb which is the key I need to use. The put on the item field now always returns the correct record. Full code posted below.
Many thanks Neal
functions:
function receipt()
{
string m_dat(8)
m_dat = dte$()
select tdpsc963.sera from tdpsc963
selectdo
m_sera = strip$(str$(tdpsc963.sera))
endselect
message("receipt")
do.update=true
m_error1=""
| Start creating a receipt
stpapi.put.field("tdpur4120m000", "tdpur045.reno", m_sera)
|* Handle question tdpur41206 yes
ret=stpapi.enum.answer( "tdpur4120m000", "tdpur41206", tcyesno.yes )
stpapi.put.field("tdpur4120m000", "form.dino", m_pack)
stpapi.put.field("tdpur4120m000", "tdpur045.suno", tdpsc971.suno)
|* Handle question tdpur41207 no
ret=stpapi.enum.answer( "tdpur4120m000", "tdpur41207", tcyesno.no )
|* Activate sub process
stpapi.handle.subproc("tdpur4120m000", "tdpsc0191s000", "add")
ret = stpapi.change.view("tdpur4120m000",m_error1)
if m_error1 <> "" then
message("Change View " & m_error1)
do.update = false
endif
select tdpsc910.item,tdpsc910.suno from tdpsc910
where tdpsc910.item = :tdpsc971.item and tdpsc910.suno = :tdpsc971.suno
as set with 1 rows
selectdo
message("found")
message(str$(tdpsc910.ddtb))
stpapi.put.field("tdpsc0191s000", "tdpsc910.ddtb", str$(tdpsc910.ddtb))
stpapi.put.field("tdpsc0191s000", "tdpsc910.item", tdpsc971.item)
endselect
ret = stpapi.find("tdpsc0191s000",m_error1)
if m_error1 <> "" then
message("Find Error " & m_error1)
do.update = false
endif
stpapi.put.field("tdpsc0191s000", "tdpsc910.mark", str$(1))
stpapi.get.field( "tdpsc0191s000", "tdpsc910.item", m_item )
|* Check tdpsc971 item found
if strip$(m_item) <> strip$(tdpsc971.item) then
stpapi.end.session("tdpsc0191s000")
stpapi.end.session("tdpur4120m000")
m_error2 = "NO SCHEDULE FOR ITEM"
message(m_item & tdpsc971.item)
else
ret=( stpapi.update( "tdpsc0191s000", do.update, m_error1 ) )
if m_error1 <> "" then
message("Update Error " & m_error1)
endif
stpapi.continue.process("tdpsc0191s000",m_error1)
if m_error1 <> "" then
message("Cont Process " & m_error1)
endif
stpapi.end.session("tdpsc0191s000")
if strip$(m_error1) = "" then
stpapi.get.field( "tdpur4120m000", "tdpur045.orno", m_orno )
stpapi.get.field( "tdpur4120m000", "tdpur045.pono", m_pono )
stpapi.get.field( "tdpur4120m000", "tdpur045.item", m_item )
message("orno " & m_orno)
message("pono " & m_pono)
message("item " & m_item)
stpapi.put.field("tdpur4120m000", "tdpur045.orno", strip$(m_orno))
stpapi.put.field("tdpur4120m000", "tdpur045.pono", strip$(m_pono))
stpapi.put.field("tdpur4120m000", "tdpur045.item", strip$(m_item))
stpapi.put.field("tdpur4120m000", "tdpur045.diqu", str$(tdpsc971.qty1))
stpapi.put.field("tdpur4120m000", "tdpur045.dqua", str$(tdpsc971.qty1))
ret=( stpapi.update( "tdpur4120m000", do.update, m_error1 ) )
if m_error1 <> "" then
message("Update Error " & m_error1)
endif
endif
stpapi.end.session("tdpur4120m000")
endif
}