JavaScript onSave Function Example 1: Nonconditional Data
This example shows you how to create or update a field on a child record from a parent. The parent Account Object has an account number field stored within it that must be saved in the Asset.
You will structure this example as an onCreate action. However, if you need to create an Asset as a top level object, then the Account Object data cannot be read when the record is created. This example is only for making an Asset from an Account.
If a user selects a customer during the quotation entry and then saves, then the account number is inserted at this point. The following assumptions are made in this example:
- The MODULEID of the parent account is 1.
- The MEFIELDNAME of the Account Number field in the parent account is ACCTTXT01.
- The MEFIELDNAME, which saves the account number in the new Asset record, is CUSTTXT08.
The typical structure of an onSave query is as follows:
function fieldsOnDefault(){ return "MEFIELDNAME"; } function getDefaultValueOfMEFIELDNAME (){ return "MODULEID.MEFIELDNAME"; }
An example of a complete onSave query with header and footer information and nonconditional data is as follows:
<html><head><title>onSaveExample1</title> <script type="text/javascript"> function fieldsOnDefault(){ return "CUSTTXT08"; } function getDefaultValueOfCUSTTXT08(){ return "2.ACCTXT01"; } </script></head><body></body></html>
where:
- fieldsOnDefault lists the field (in this example, CUSTTXT08) that is to be updated in the MEFIELDNAME parameter. The code in onSave example 1 is as follows: function fieldsOnDefault(){ return "CUSTTXT08"; }
- getDefaultValueOfMEFIELDNAME() writes a value to the field and the value to return (in this example, "1.ACCTXT01"). The code in onSave example 1 is as follows: function getDefaultValueOfCUSTTXT08 (){ return "2.ACCTTXT01"; }