Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / Will adding JS to a Qu...
Sales forum
Suggested answer

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

Posted on by 146

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?

Categories:
  • Guido Preite Profile Picture
    Guido Preite 54,061 Moderator on at
    RE: Will adding JS to a Quick Create Form opened from a Subgrid work?

    you can generate the code using my tool Dataverse REST Builder

  • Joseph Nasr Profile Picture
    Joseph Nasr 146 on at
    RE: Will adding JS to a Quick Create Form opened from a Subgrid work?

    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?

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,061 Moderator on at
    RE: Will adding JS to a Quick Create Form opened from a Subgrid work?

    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.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,263 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,112 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans