Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Javascript for Editable Grid

Posted on by 1,299

Hi Experts,

I am trying to write a Javascript on the Editable grid(of opportunity product) that gets triggered onrecordselect. I want to get data from the related record and based of that manuplate the editable grid.

Ex. We have a custom field on the product called "New" which is "Yes" or "No", I want to retrieve the value of the field in the javascript so that i can manipulate the editable grid based of that.

The code that i have now is able to select or read data from the selected row which is "Opportunity product", from here how to i read "Product" (Existing product) which is a lookup- a related entity. Please help me out

function gridRowSelected(executionContext) {
var selected = executionContext.getFormContext().data.entity;
var Width= selected.attributes.getByName("as_width").getValue();
}

Thanks in advance for your response.

  • Davyjones Profile Picture
    Davyjones 1,299 on at
    RE: Javascript for Editable Grid

    Thanks for your response and help. Appreciate it a lot

  • Verified answer
    PabloCRP Profile Picture
    PabloCRP 1,086 on at
    RE: Javascript for Editable Grid

    Hi, Davyjones

    You'll get just those 3 items form a lookup, for getting more data use Xrm.WebApi

    function foo(){
    var selected = executionContext.getFormContext().data.entity;
    var lookUpGrid = selected.attributes.getByName("NAME_OF_THE_FIELD").getValue()?.[0];
    if(lookUpGrid===undefined)
        return;
    Xrm.WebApi.retrieveRecord(lookUpGrid?.entityType,lookUpGrid?.id).then(
    function(res)
    {
        //your record will log with a lot of fields.
        console.log(res);
    },
    function(err)
    {
        //something gone wrong.
        console.log(err);
    });
    
    }

    Regards.

    please consider marking as an answer if it was helpful

  • Davyjones Profile Picture
    Davyjones 1,299 on at
    RE: Javascript for Editable Grid

    Hi Pablo,

    Thank you for your response.

    I added the lookup in the editable grid in the view and i was able to get the array, but the array did not have all the fields on the record, rather it had only the name, id and the array pointer.

    Please help.

  • PabloCRP Profile Picture
    PabloCRP 1,086 on at
    RE: Javascript for Editable Grid

    Hi, Davyjones .

    where is the lookup in the editable grid?, can you add that field to the view that is using your grid?

    then you could do the same as you are doing

    data.entity.attributes.getByName("NAME_OF_THE_FIELD").getValue(), and it'll give you a array with an object as result.

    Regards.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans