Hello,
I have 2 entities/Tables: Backlog and Cashflow. The Backlog's Main Form has a subgrid that opens a Cashflow Quick Create Form, to create multiple Cashflows related to that Backlog. What I'm trying to achieve with Javascript is: if that Cashflow Subgrid contains records, hide the 'Year Choice' field, else show it for the user to input the first record's Year.
Image:

Code:
function hideYearChoiceInput(executionContext) {
//Initiated Form Context.
var formContext = executionContext.getFormContext();
//get Subgrid Control
var grid = Xrm.Page.getControl("Backlog_cashflows_subgrid");
//make sure the grid has loaded
if (grid == null) {
setTimeout(function () {CheckRows();}, 2000);
return;
}
var filteredRecordCount = grid.getGrid().getTotalRecordCount();
if(filteredRecordCount == 0) {
formContext.getControl("cra1c_yearchoice").setVisible(true);
}
else {
formContext.getControl("cra1c_yearchoice").setVisible(false);
}
}
Do I add this code and web resource to the Cashflow Quick Create Form?