PDA

View Full Version : AutoCode File Maintenance PassAddEditChecks


GordS
03-20-2010, 03:30 PM
I am new to Valence. The first program I was trying to create was a simple file maintenance program that had only 2 fields. Both fields are required.

I created the program with no problems and it works based on what the AutoCode File Maintenance option does. I then added in the edit checks. I have tried it several times and I do not get the results I am expecting.

I expect the message I sent to be displayed. Instead I get "An error occurred when attempting to Add a record". I looked at the generated code and there is a catch all if it gets garbage back from the program.

I checked my code and the Repsonse in Firebug and it looks correct. I filled in the fields and was able to add the record.

What is casuing my problem?

sean.lanktree
03-20-2010, 04:47 PM
Can you post the code? Specifically the javascript function fnAddRecord and the back-end procedure PassAddEditChecks? Additionally, post the response too.

GordS
03-20-2010, 05:06 PM
Here is the JavaScript code you requested.

// function to handle adding a record...
// if called with submit=true...then it will initiate the ajax call to the back-end program
// otherwise, simply display the add window
function fnAddRecord(submit){
if (submit == true){
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
action: 'addRecord',
pgm: 'APMOBSERVR',
OGCODE:Ext.getCmp('add_OGCODE').getValue(),
OGDESCRIPT:Ext.getCmp('add_OGDESCRIPT').getValue()
},
success: function(response){
var check = response.responseText;
if (check) {
var data = Ext.util.JSON.decode(response.responseText);
if (data.SUCCESS == '1') {
Ext.get('addWindow').switchOff({
duration: 1,
callback: function(){
Ext.getCmp('addWindow').hide();
parent.showMessage('','<b><center>Record Added</b></center>');}}) dsMainAPMOBSERVRGrid.reload();
} else {
try {
Ext.getCmp(data.FLD).markInvalid(data.MSG);
Ext.getCmp(data.FLD).focus();
} catch(e){
Ext.Msg.alert('Error','An error occured when attempting to add a new record');
}
}
}
},
failure: function(){ Ext.getBody().unmask();
Ext.Msg.alert('Failure','Failed to receive a response from server');
} }) } else{ Ext.getCmp('addWindow').show(); } }

Here is the code from PassAddEditChecks.

p PassAddEditChecks...
p b
d pi n

/free
// enter any edit checks for adding a record here...
// use the following format:
// where FIELDNAME represents the actual name of the field in error...
//
// if post_FIELDNAME = *blanks;
// vvOut_toJsonPair('SUCCESS:0,FLD:add_FIELDNAME,MSG: Error message');
// return FALSE;
// endif;
//
If post_OGCODE = *Blanks;
vvOut_toJsonPair('SUCCESS:0,FLD:OGCODE,MSG:Observe r required');
return FALSE;
EndIf;
return TRUE;
/end-free
p e

Here is the response I see in Firebug.

{"SUCCESS":"0","FLD":"OGCODE","MSG":"Observer required"}

Your help is appreciated.

GordS
03-20-2010, 05:09 PM
Just after I sent you the information. I looked at the javascript code I included in my reply. I noticed that I needed to send back FLD add_OGCODE instead of FLD OGCODE. Rooike mistake. Thanks.