eric.dizon
15th August 2014, 23:26
I am trying to use the session in AFS whinh4525m000 - but my goal is to find a specific run number, open the records so I can update the lot number it is using and then save and close the dialog that was open. Can anybody give me an example on how to do this.

In multi-occurrence session in AFS how do I ?
1. Use the proper index in order to initiate a find command
2. When the record is located, open the dialog and update the lot number from the session
3. Save and close the update for the lot number.

Regards,

Eric

mark_h
16th August 2014, 04:14
This is the correct form for this thread. There are really two ways that in a multi-occurrence session to find records. There is the stpapi.change.view or just a simple find will work - you can test the return results to make sure you have the correct record. As for the index - I can't say for sure in LN, but in 4c4 I never really could find a way to change the index after starting a session. But what I did do once was just clone the session itself. Basically I copied the session record - left all forms and scripts the same as the original. In the new session I just changed which index was the primary index for the session. Then when I start it using api code I could just put the fields and using stpapi.find.

Question 2 I really can't answer since I am not familiar with LN. In 4c4 once I find the lot I just put the new lot and run stpapi.update or stpapi.save to update it. With out knowing LN I can't talk about what it might take to change the lot. Sounds like you have to open another session.

You can search this forum for the session and maybe find something you can build on or model your session after.

bhushanchanda
16th August 2014, 08:51
Hi,

If you just want to update Lot Code against a specific Run Number, why are you using AFS? You can simple use DAL and update the record. Why to make things complicated when you have simpler ways. If it was about processing a record, you could have used AFS/DLL's but if you just have to update Lot code, try using DAL.

Note:- In some situations where just an update is required, DAL won't work but AFS will.

eric.dizon
19th August 2014, 20:05
Hi Mark,

I believe AFS behaves like a macro, there is a need to change index because the run number is defaulted to Index 2 in the form. We don't have source code to do the suggestion you did like copy the form and change the index.


Hi bhushanchanda,

I needed to use AFS because for Lot numbers once LN creates the outbound advice it will select any Lot number and create an allocation for it. If I don't use AFS and just poke the value of the Lot number in whinh225, the allocation initially designated by Outbound Advice does not get removed/reallocated causing inventory issues.

bhushanchanda
19th August 2014, 20:16
Hi,

Why don't you handle it initially then? I mean, creating outbound advice with the required lot number?

And, if this doesn't full fill the requirement, you can try deleting the old record with DAL and then inserting the new one. I guess that might not cause any issues.

But anyways, it can be done through AFS as well. Can you put your script? It wont be tougher assuming that their is no misbehaving session. The session doesn't have any view fields so you can directly use stpapi.insert's and do a stpapi.find(). If record found, do stpapi.mark(). Open synchronized dialog in modify mode, put your lot code and do stpapi.update and stpapi.save.

You can use this kind of logic:-

stpapi.put.field( "ticst0101m100", "ticst001.pdno", tigil002.pdno)
ret = stpapi.change.view( "ticst0101m100", error )
stpapi.put.field( "ticst0101m100", "ticst001.pono", str$(tigil000.pono) )
ret = stpapi.find( "ticst0101m100" , err )
if ret = 1 then
ret = stpapi.mark( "ticst0101m100" , err )
ret = stpapi.synchronize.dialog("ticst0101m100", "modify", err.msg)
stpapi.put.field( "ticst0101m100", "ticst001.issu", str$(tigil005.issu) )
stpapi.put.field( "ticst0101m100", "ticst001.dris", str$(1) )
ret = stpapi.update( "ticst0101m100", TRUE, err )
if ret = 1 and isspace(error) then
stpapi.save( "ticst0101m100", err )
else
stpapi.recover( "ticst0101m100", err )
endif
endif

stpapi.end.session( "ticst0101m100" , err )
stpapi.end.session( "ticst0101m100" , errr1 )

In above case there was a view field but your session does not have one so you can ignore that.


Thread (http://www.baanboard.com/baanboard/showthread.php?t=64487)

eric.dizon
19th August 2014, 20:22
Hi bhushandchanda,

Here is my code it is not complete yet, I am trying to experiment based on your pointers and mark_h but getting a "Editable Synchronize not started". Can you please verify and advise. Thanks.

=baanfunction domain tcyesno afs.update.outbound.clot(domain whinh.btno l.runn, domain tcorno l.orno, domain tcpono l.pono)
{
domain tcibd.sern l.serl
domain tcyesno l.outb

string o.dummy.error(100)
string o.error.mess.last(100)
string errmsg(100)
string dummy.msg(1)

domain tcibd.sern l.clot
long ret, ret1



|Retrieve Order Set from Warehouse Orders

|Retrieve Lot Number from CTL Lines detail
select cxcsb010.mser:l.serl
from cxcsb010
where cxcsb010._index1 = {:l.orno, :l.pono}
as set with 1 rows
selectdo
endselect

if not isspace(l.serl) then
|AFS Method of Changing Lot numbers

|"whinh4525m000"
|Find runnumber, oorg, orno, oset, pono, seqn, sern
|Index1 : oorg, orno, oset, pono, seqn, sern
|Index2 : runn + index1

stpapi.put.field( "whinh4525m000", "whinh225.runn", l.runn )
stpapi.put.field( "whinh4525m000", "whinh225.orno", l.orno )
ret = stpapi.find( "whinh4525m000" , o.error.mess.last)
if ret <> 1 then
|if not isspace(o.error.mess.last) then |if ret value is validated it fails
ret = stpapi.recover("whinh4525m000", o.dummy.error)
stpapi.end.session("whinh4525m000") |
suspend (1000)
return(tcyesno.no)
else
stpapi.get.field("whinh4525m000", "whinh225.clot", l.clot)
message(l.clot)
stpapi.put.field("whinh4525m000", "whinh225.clot", l.serl)
ret = stpapi.update("whinh4525m000", true, errmsg )

|ret1 = stpapi.save("whinh4525m000", o.dummy.error)
if ret then
l.outb = tcyesno.yes
else
l.outb = tcyesno.no
endif
stpapi.end.session("whinh4525m000")
endif
else
l.outb = tcyesno.no
endif


return(l.outb)
}

bhushanchanda
19th August 2014, 20:36
Hi,

The first question:-

Are you able to successfully find the record? Because you are using Run No which is not a part of Index 1. If you are not able to find, use Order Origin, No, Set, Position,Seq,Advice.

Now, first do a stpapi.put.field() and put all the fields required to search the record. Once done, do a stpapi.find(). If it returns proper value, do this:-

ret = stpapi.mark( "whinh4525m000" , err )
ret = stpapi.synchronize.dialog("whinh4525m000", "modify", err.msg)
stpapi.put.field( "whinh4525m000", "whinh225.clot", new_lot )
ret = stpapi.update( "whinh4525m000", TRUE, err )
if ret = 1 and isspace(error) then
stpapi.save( "whinh4525m000", err )
else
stpapi.recover( "whinh4525m000", err )
endif

eric.dizon
19th August 2014, 21:00
Hi,

I was able to find the record and what you gave me for a sample worked. You are life saver and a miracle worker :). But the question is if that didn't work what is the command to switch the index?


This is the code that is working for now :

stpapi.put.field( "whinh4525m000", "whinh225.runn", l.runn )
stpapi.put.field( "whinh4525m000", "whinh225.orno", l.orno )
ret = stpapi.find( "whinh4525m000" , o.error.mess.last)
if ret <> 1 then
ret = stpapi.recover("whinh4525m000", o.dummy.error)

stpapi.end.session("whinh4525m000") |
suspend (1000)
return(tcyesno.no)
else
stpapi.get.field("whinh4525m000", "whinh225.clot", l.clot)
message(l.clot)

ret = stpapi.mark("whinh4525m000", err)
ret = stpapi.synchronize.dialog("whinh4525m000", "modify", errmsg)
stpapi.put.field("whinh4525m000", "whinh225.clot", l.serl)
ret = stpapi.update("whinh4525m000", TRUE, errmsg )
if ret = 1 and isspace(errmsg) then
|ret1 = stpapi.save("whinh4525m000", o.dummy.error)
stpapi.save("whinh4525m000", err)
l.outb = tcyesno.yes
else
stpapi.recover("whinh4525m000", err)
l.outb = tcyesno.no
endif
stpapi.end.session("whinh4525m000", err)
stpapi.end.session("whinh4525m000", errmsg)

bhushanchanda
20th August 2014, 07:54
Glad it worked. There is no way to change the index. A workaround is what Mark said, cloning the session. But, if it works for you no need to worry. :)