Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Alert If there is no record in subgrid

(0) ShareShare
ReportReport
Posted on by 940

Hi All,

The scenario is if in the subgrid there is no record then on-load/on-save it pop-up a message using javascript.

Please suggest, If, Is there any way to do the same.

Thanks in advance.

*This post is locked for comments

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Alert If there is no record in subgrid

    Yes you are right ,put a check on form type == 2 .

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/formContext-ui/getFormType

  • RE: Alert If there is no record in subgrid

    Hi Goutam Das,

    Thanks for your response!

    As you suggested, that register the function in the forms onSave event.

    But this is not working because when I am going to create a new case record and then hit the save button without added any record in subgrid it is showing the notification and prevent save functionality which is good.

    But I guess without save the new record I am unable to add a record from subgrid because (+) button of subgrid is not visible. This is only visible after save the record.

  • Suggested answer
    Ammar Zaied Profile Picture
    Ammar Zaied 1,670 on at
    RE: Alert If there is no record in subgrid

    You can develop custom plugin

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Alert If there is no record in subgrid

    Hi Shanti,

    Straight forward way its not possible using OOB workflow as you can not get child record inside workflow. So if you need server side validation go for plugin or custom workflow otherwise do client side script.

  • RE: Alert If there is no record in subgrid

    Is there any other way to do this without Script?

    Just asking for information!

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Alert If there is no record in subgrid

    Hi Shakti ,

    Try with this , instead of alert show form notification . Register this function in the forms onsave  event of the forms . Dotnt forget to replace subgrid id .

    function ValidateSelectedStageOnSave(context) {
    var count = 0;
    //Replace the subgrid name in below
    if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("subgridcompetitorid") != null && Xrm.Page.getControl("subgridcompetitorid") != undefined) {
    count = Xrm.Page.getControl("subgridcompetitorid").getGrid().getTotalRecordCount();
    }
    if (count == -1 || count == 0) {
    Xrm.Page.ui.setFormNotification("Please add at least one competitor", "INFO", "2001"); // Set notification
    context.getEventArgs().preventDefault();
    return false;
    }
    else {
    Xrm.Page.ui.clearFormNotification("2001"); // Clear notification
    }

    }

  • Suggested answer
    Ammar Zaied Profile Picture
    Ammar Zaied 1,670 on at
    RE: Alert If there is no record in subgrid

    Hi Shakti,

    Use the script below: 

    if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("Name_Of_SubGrid") != null && Xrm.Page.getControl("Name_Of_SubGrid") != undefined) {

    var count = Xrm.Page.getControl("Name_Of_SubGrid").getGrid().getTotalRecordCount();

    alert("Records:"+count);

    }

    can you visit the link to show more about Sub Grid:

    https://community.dynamics.com/crm/b/mscrmcustomization/posts/sub-grid-client-side-script-methods

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans