amiverma29
27th February 2015, 10:51
Hi,

I created a AFS for create planned order and planned order distribution. while inserting record in session cprrp1105m000 from AFS it returns zero in stpapi.change.view() and gives error in insert.

Steps:
1. put fields in cprrp1100m000
2. find
3. form.command() ** Order distribution
4. put view fields in cprrp1105m000
5. ret = change.view
6. ret value is zero and error is blank in change.view

please suggest.

thanks in advance...

bhushanchanda
27th February 2015, 11:03
Hi,

I do not see Mark record before form command? Are you marking the record?

amiverma29
27th February 2015, 11:23
Hi Bhushan,
Yes mark record is there already.
I forgot to mention mark.record above.

bhushanchanda
27th February 2015, 11:27
Hi,

If possible post your code. Also, what error message are you getting on insert?

amiverma29
27th February 2015, 11:43
Hi Bhushan,


stpapi.put.field("cprrp1100m000","cprrp100.plnc",i.plnc)
stpapi.put.field("cprrp1100m000","cprrp100.type",str$(i.type))
stpapi.put.field("cprrp1100m000","cprrp100.orno",i.orno)
ret = stpapi.find("cprrp1100m000",err.msg)
if ret then
ret1 = stpapi.mark("cprrp1100m000",err.msg)
if ret1 then
stpapi.form.command("cprrp1100m000", 5, "start.order.distribution", err.msg)
stpapi.put.field("cprrp1105m000","cprrp105.plnc",i.plnc)
stpapi.put.field("cprrp1105m000","cprrp105.koor",str$(i.type))
stpapi.put.field("cprrp1105m000","cprrp105.orno",i.orno)
ret2 = stpapi.change.view("cprrp1105m000",err.msg)
if ret2 then
stpapi.put.field("cprrp1105m000","cprrp001.cprj",i.cprj)
stpapi.put.field("cprrp1105m000","cprrp001.cspa",i.cspa)
stpapi.put.field("cprrp1105m000","cprrp001.cact",i.cact)
stpapi.put.field("cprrp1105m000","cprrp105.oqan",str$(i.oqan))
ret1 = stpapi.insert("cprrp1105m000",true,ret.err)
endif

if we comment "if ret2 then"
Error in insert:
"Enter a value for Project field.
Reason: Project is mandatory, because item XYZ has field Mandatory Project Peg Yes."

bhushanchanda
27th February 2015, 11:54
Hi,

I guess there are 4 view fields for session cprrp1105m000. Add the position as well. Also, you are missing one find there.

Try adding

ret = stpapi.find("cprrp1105m000",err.msg)

after putting 4 view fields.

If that doesn't work, simple do a change.view and then put your fields.

One more suggestion - If on LN and you are just doing inserts, better to go with DAL.

mark_h
1st March 2015, 14:40
You can always skip the change view - just put all the fields on the form and do an insert. If necessary you can check the return value of the insert. Just make sure you put all the fields including the view fields.

stpapi.form.command("cprrp1100m000", 5, "start.order.distribution", err.msg)
stpapi.put.field("cprrp1105m000","cprrp105.plnc",i.plnc)
stpapi.put.field("cprrp1105m000","cprrp105.koor",str$(i.type))
stpapi.put.field("cprrp1105m000","cprrp105.orno",i.orno)
stpapi.put.field("cprrp1105m000","cprrp001.cprj",i.cprj)
stpapi.put.field("cprrp1105m000","cprrp001.cspa",i.cspa)
stpapi.put.field("cprrp1105m000","cprrp001.cact",i.cact)
stpapi.put.field("cprrp1105m000","cprrp105.oqan",str$(i.oqan))
ret1 = stpapi.insert("cprrp1105m000",true,ret.err)

amiverma29
2nd March 2015, 05:29
Hi MArk,
I tried your solution also but it gives error
"Enter a value for Project field.
Reason: Project is mandatory, because item XYZ has field Mandatory Project Peg Yes."

bhushanchanda
2nd March 2015, 09:07
Hi Bhushan,


stpapi.put.field("cprrp1100m000","cprrp100.plnc",i.plnc)
stpapi.put.field("cprrp1100m000","cprrp100.type",str$(i.type))
stpapi.put.field("cprrp1100m000","cprrp100.orno",i.orno)
ret = stpapi.find("cprrp1100m000",err.msg)
if ret then
ret1 = stpapi.mark("cprrp1100m000",err.msg)
if ret1 then
stpapi.form.command("cprrp1100m000", 5, "start.order.distribution", err.msg)
stpapi.put.field("cprrp1105m000","cprrp105.plnc",i.plnc)
stpapi.put.field("cprrp1105m000","cprrp105.koor",str$(i.type))
stpapi.put.field("cprrp1105m000","cprrp105.orno",i.orno)
ret2 = stpapi.change.view("cprrp1105m000",err.msg)
if ret2 then
stpapi.put.field("cprrp1105m000","cprrp001.cprj",i.cprj)
stpapi.put.field("cprrp1105m000","cprrp001.cspa",i.cspa)
stpapi.put.field("cprrp1105m000","cprrp001.cact",i.cact)
stpapi.put.field("cprrp1105m000","cprrp105.oqan",str$(i.oqan))
ret1 = stpapi.insert("cprrp1105m000",true,ret.err)
endif

if we comment "if ret2 then"
Error in insert:
"Enter a value for Project field.
Reason: Project is mandatory, because item XYZ has field Mandatory Project Peg Yes."


Why are you inserting values in cprrp001 table? What is the order type?

Also, are you able to do it manually? Recheck the fields and the values again. And, check if the item for the order in cprrp100 has project attached. If yes, try to insert the value in that prior to calling Order Distribution. Looks like one more example of incorrect coding in standard session.