Trigger wont validate

Posted by ByronB on 04-Feb-2015 06:18

Hi I am trying to get a trigger working with an update statement, I keep getting "Field "From Relationship" must have a value (line #20)" error and have no idea why? All the correct values are being returned?

var fromAcc = {!associationFromAccount};
var toAcc = {!associationToAccount};

var assocRecId = rbv_api.selectQuery("select id from association where associationToAccount = ? and associationFromAccount = ?", 1, fromAcc, toAcc); 

var currentRecord = rbv_api.selectQuery("select id, fromDescription, toDescription, associationFromAccount, fromRelationship, associationToAccount, toRelationship from association where id = ?", 1, {!id}); 

var arr = new Array();
//arr['id'] = currentRecord[0][0];
arr['toDescription'] = currentRecord[0][1];
arr['fromDescription'] = currentRecord[0][2];
arr['associationToAccount'] = currentRecord[0][3];
arr['toRelationship'] = currentRecord[0][4];
arr['associationFromAccount'] = currentRecord[0][5];
arr['fromRelationship'] = currentRecord[0][6];

rbv_api.printArr(assocRecId);
rbv_api.updateRecord("association", assocRecId[0][0], arr);

I also have a trigger to delete in the same fashion but cant get the formula to validate:

var fromAcc = {!associationFromAccount};
var toAcc = {!associationToAccount};
//rbv_api.println(fromAcc + "|" + toAcc);
var assocRecId = rbv_api.selectQuery("select id from association where associationToAccount = ? and associationFromAccount = ?", 1, fromAcc, toAcc); 
//rbv_api.printArr(assocRecId);
rbv_api.println(assocRecId[0][0]);
rbv_api.deleteRecord('association', assocRecId[0][0]);


If I use: 

rbv_api.deleteRecord('association', assocRecId); - The formula validates but doesnt work.

If I use:
rbv_api.deleteRecord('association', assocRecId[0][0]); - The formula doesnt validate but works...

All Replies

Posted by Godfrey Sorita on 04-Feb-2015 08:41

Hi Byron,

What is the field type of "fromRelationship"? What is the the value of currentRecord[0][6] during runtime?

You can check the value using rbv_api.log() on your object script. This creates a log entry in the specified system log file (e.g. "debug"). After running a sample transaction on the target object, you should be able to see the log entries by editing any trigger and clicking the "Log" button.


Regards,
Godfrey

Posted by ByronB on 04-Feb-2015 08:49

Hi Godfrey

fromRelationship is a picklist and the value returned is 43427, there really is only 1 picklist item for fromRelationship and toRelationship.

Posted by ByronB on 04-Feb-2015 08:58

I have simplified the script, first select was not needed I think:

var fromAcc = {!associationFromAccount};
var toAcc = {!associationToAccount};

var assocRecId = rbv_api.selectQuery("select id from association where associationToAccount = ? and associationFromAccount = ?", 1, fromAcc, toAcc); 

var arr = new Array();
arr['toDescription'] = '{!fromDescription}';
arr['fromDescription'] = '{!toDescription}';
arr['associationToAccount'] = '{!associationFromAccount#id}';
arr['toRelationship'] = '{!fromRelationship#id}';
arr['associationFromAccount'] = '{!associationToAccount#id}';
arr['fromRelationship'] = '{!toRelationship#id}';

rbv_api.printArr(arr);
rbv_api.updateRecord("association", assocRecId[0][0], arr);

Same error though....

Posted by ByronB on 04-Feb-2015 10:02

Hi Godfrey

The issue is that fromRelationship and toRelationship are required fields, once I marked them as not required the script still wouldnt validate but the trigger would work.

Not sure why but those fields are clearing the values out for some reason, when I create the association the from and to relationship values are retained but as soon as I edit the record those values are cleared out. I have tried deleting and recreating the fields themselves but the behavior is still there. There are no script components running on the edit form in case you were going to ask :-)

Posted by Godfrey Sorita on 04-Feb-2015 11:59

I was able to reproduce the issue on updateRecord which does not save the value of the picklist fields. The solution is to parse the value into integer so the value will be saved.

For example: 

arr['toRelationship'] = parseInt( currentRecord[0][4] );

or 

arr['toRelationship'] = {!fromRelationship#id};

I can't reproduce the issue when validating the trigger, though. May I know what version are you using?

This thread is closed