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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 144 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 59

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans