Hi Folks,
I have the one subgrid (accounts) and lookup (accounts) as below. My requirement is as below
1. if there is only one record in the Subgrid, I should set that record as a main funder as per the screenshot 1
2. if there are more than one records, user should choose the value as per the screenshot 2. So I was able to set the Main funder from the Main funder List.
Note - Main Funders drop down is filtered with the values in the Funders Grid.
if the user intially add one funder, the Main funder is defaulted to the one and only funder in the list, when they add the second one in the funders list, Im clearing the value with null.
My JS script is as below
var onLoad = function (executionContext) {
var formContext = executionContext.getFormContext();
getFunders(executionContext);
let fundersSubgrid = formContext.getControl(/FundersSubGrid/);
if (fundersSubgrid != null) {
let rowFundersCount = fundersSubgrid.getGrid().getTotalRecordCount();
fundersSubgrid.addOnLoad(function () {
getFunders(executionContext);
setControlDisabled(formContext, /svdp_mainfunder/, false);
var gridColumns = [];
let currentFundersRowCount = fundersSubgrid.getGrid().getTotalRecordCount();
let gridRows = fundersSubgrid.getGrid().getRows();
//loop through each row to get values of each column
if (gridRows.getLength() > 0) {
gridRows.forEach(function (row, i) {
gridColumns = row.getAttribute();
if (currentFundersRowCount === 1) {
gridColumns.forEach(function (column, j) {
if (column.getName() == /name/) {
setControlDisabled(formContext, /svdp_mainfunder/, true);
setAttributeRequiredLevel(formContext, /svdp_mainfunder/, /required/);
setLookupValue(formContext, /svdp_mainfunder/, row.getData().getEntity().getEntityName(), row.getData().getEntity().getId(), column.getValue());
}
});
} else if (currentFundersRowCount === 0) {
setAttributeRequiredLevel(formContext, /svdp_mainfunder/, /none/);
setAttribute(formContext, /svdp_mainfunder/, null);
} else if (currentFundersRowCount > 1) {
setAttributeRequiredLevel(formContext, /svdp_mainfunder/, /none/);
setAttribute(formContext, /svdp_mainfunder/, null);
}
else {
setAttributeRequiredLevel(formContext, /svdp_mainfunder/, /required/);
setAttribute(formContext, /svdp_mainfunder/, null);
}
});
}
else {
setAttributeRequiredLevel(formContext, /svdp_mainfunder/, /none/);
setAttribute(formContext, /svdp_mainfunder/, null);
}
if (currentFundersRowCount != rowFundersCount) {
refreshGrid(formContext, /FundersSubGrid/);
console.log(/FundersSubGrid refreshed/);
rowFundersCount = currentFundersRowCount;
}
});
}
}
My Issue here is as below
when I set the Main funder from the drop down for the multiple funders list and save the record or re-load the record, the value is getting cleared because of the null
setAttribute(formContext, /svdp_mainfunder/, null);
Is there any way to skip to run the addOnload on Save or Reload of the Record ?