How to retrieve data from an sub-grid using JavaScript in D365 CE?

Introduction

In this blog, we will discuss how we can fetch data directly from sub-grid without using FetchXML in JavaScript.

It is always easy to fetch the data from the fields on form but what about fetching the data from the sub-grid added on the forms?

Here is how we can achieve this :

Example

Suppose we have Employee form with Skills sub-grid added to it. We want to fetch the names of  skills from sub-grid and append skill names in Skills field on Employee form.

The javascript code will look like :

Result