GET/SET different field values using JavaScript and generate unique name...
code:
function generateUniqueName(executionContext) {
// Get the form context from the execution context
var formContext = executionContext.getFormContext();
// Get the values of the customer, bank account, and loan type fields
var customerLookup = formContext.getAttribute("abc_customer").getValue();
var bankAccountLookup = formContext.getAttribute("abc_bankaccount").getValue();
var loanType = formContext.getAttribute("abc_loantype").getText();
// Check if a customer is selected and the loan type is "Personal Loan" or "Car loan"
if (customerLookup && (loanType == "Personal Loan" || loanType == "Car loan")) {
// Extract relevant information from the customer lookup field
var customerName = customerLookup[0].name;
var customerId = customerLookup[0].id;
// Generate a unique ID based on customer name, loan type, and customer ID
var uniqueId = loanType.substring(0, 4) + "-" + customerName.substring(0, 4) + "-" + customerId.substring(1, 5);
// Convert uniqueId to uppercase
uniqueId = uniqueId.toUpperCase();
// Set the generated unique ID to the Name field
formContext.getAttribute("abc_name").setValue(uniqueId);
}
// Check if the loan type is "Home Loan"
else if (loanType == "Home Loan") {
// Extract relevant information from the bank account lookup field
var bankAccountName = bankAccountLookup[0].name;
var bankAccountId = bankAccountLookup[0].id;
// Generate a unique ID based on bank account name, loan type, and bank account ID
var uniqueId = loanType.substring(0, 4) + "-" + bankAccountName.substring(0, 4) + "-" + bankAccountId.substring(1, 5);
// Convert uniqueId to uppercase
uniqueId = uniqueId.toUpperCase();
// Set the generated unique ID to the Name field
formContext.getAttribute("abc_name").setValue(uniqueId);
}
}
Comments
Post a Comment