rduncan10
12th December 2012, 16:30
I'm having problems with an AFS session that runs in a batch job. Sometimes it does not terminate correctly and leaves the batch job user logged in.
Here is the situation:
We sell many phantom items. When the user enters these on the sales order, they need to change the "Issue Status" field to "Issue Main Item". Of course they forget, so I wrote a session to fix this and run it in a batch job. The script looks like this:
...First it runs SQL to find any order lines with "Issue Components"
stpapi.put.field("tdsls4101m000", "tdsls040.orno", str$(i.orno))
ret = stpapi.find("tdsls4101m000")
stpapi.handle.subproc("tdsls4101m000", "tdsls4102s000", "add")
stpapi.continue.process("tdsls4101m000", err.msg)
stpapi.put.field("tdsls4102s000", "tdsls041.pono", str$(i.pono))
ret = stpapi.find("tdsls4102s000")
stpapi.put.field("tdsls4102s000", "tdsls041.isss", str$(tcisss.issue.main))
**SEE NOTE**
if stpapi.update("tdsls4102s000", true, err.msg) = 0 then
stpapi.recover("tdsls4102s000", err.msg)
endif
stpapi.end.session("tdsls4102s000")
stpapi.end.session("tdsls4010m000")
The problem is that sometimes the line gets delivered before the batch job runs. When this happens, the err.msg value in the stpapi.update() function will be "Deliveries already entered...". Changing the line is not possible.
If I run this session manually, stpapi.recover() and stpapi.end.session() do their job and the session ends.
I'm not really sure what happens in the batch job. The log shows the session ends, and no errors are thrown, but the batch job user stays logged in after the batch job ends.
I realize that I could just change the query to filter out delivered orders. But and AFS session could run into other messages and errors, and I would like to see if there is a way to handle this in AFS itself.
Here is the situation:
We sell many phantom items. When the user enters these on the sales order, they need to change the "Issue Status" field to "Issue Main Item". Of course they forget, so I wrote a session to fix this and run it in a batch job. The script looks like this:
...First it runs SQL to find any order lines with "Issue Components"
stpapi.put.field("tdsls4101m000", "tdsls040.orno", str$(i.orno))
ret = stpapi.find("tdsls4101m000")
stpapi.handle.subproc("tdsls4101m000", "tdsls4102s000", "add")
stpapi.continue.process("tdsls4101m000", err.msg)
stpapi.put.field("tdsls4102s000", "tdsls041.pono", str$(i.pono))
ret = stpapi.find("tdsls4102s000")
stpapi.put.field("tdsls4102s000", "tdsls041.isss", str$(tcisss.issue.main))
**SEE NOTE**
if stpapi.update("tdsls4102s000", true, err.msg) = 0 then
stpapi.recover("tdsls4102s000", err.msg)
endif
stpapi.end.session("tdsls4102s000")
stpapi.end.session("tdsls4010m000")
The problem is that sometimes the line gets delivered before the batch job runs. When this happens, the err.msg value in the stpapi.update() function will be "Deliveries already entered...". Changing the line is not possible.
If I run this session manually, stpapi.recover() and stpapi.end.session() do their job and the session ends.
I'm not really sure what happens in the batch job. The log shows the session ends, and no errors are thrown, but the batch job user stays logged in after the batch job ends.
I realize that I could just change the query to filter out delivered orders. But and AFS session could run into other messages and errors, and I would like to see if there is a way to handle this in AFS itself.