web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Will adding JS to a Quick Create Form opened from a Subgrid work?

(0) ShareShare
ReportReport
Posted on by 183

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:

58006.Capture.JPG

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?

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    you can't reference a grid of the other form.

    In your case as the lookup "Backlog's Cashflow" is filled, you retrieve (using Xrm.WebApi) the cashflows connected to the selected backlog and hide/show the year field accordingly.

  • Joseph Nasr Profile Picture
    183 on at

    Hey alright that's what I was wondering. I got confused because the quick create is for the Cashflow Entity, the subgrid is related to the Cashflow entity, while the Form is for Backlog.

    On a side note, may I ask how should the code be modified if I were to use Xrm.WebApi.retrieveMultipleRecords ? Especially if I were to filter based on a lookup field?

  • Guido Preite Profile Picture
    54,086 Moderator on at

    you can generate the code using my tool Dataverse REST Builder

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 118 Super User 2026 Season 1

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 46 Most Valuable Professional

#3
NeerajPawar Profile Picture

NeerajPawar 41

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans