Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)
Suggested answer

Remove option frmo editable grid in D365

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi

I need to remove on option from the optionset field in editable grid in D365 using javascript or Jquery

Is it possible or not?

*This post is locked for comments

  • yleclerc Profile Picture
    yleclerc 1,547 on at
    RE: Remove option frmo editable grid in D365

    This code finally worked:

    function preventOption(executionContext) {

       var executionEntity = (executionContext.getFormContext().data.entity);

       var statutField = executionEntity.attributes.getByName("new_statutdelatache");

       var statutValue = statutField.getValue();

       var field = statutField.controls.getByIndex(0);

       if (statutValue === 100000005 || statutValue === 100000008) {

           var actionCollection =

                   {

                       //message: 'Vous ne pouvez pas sélectionner cette valeur directement. Ces valeurs sont assignées via workflow seulement.'

                       actions: null

                   };

           actionCollection.actions = [function () {

               field.clearNotification('1');

           }];

           field.addNotification({

               messages: ['Vous ne pouvez pas sélectionner cette valeur directement. Ces valeurs sont assignées via workflow seulement.'],

               notificationLevel: 'ERROR',

               uniqueId: '1'

           }

               );

           actions[actionCollection];

           return false;

       }

       else {

               field.clearNotification(1);

           }

    }

  • yleclerc Profile Picture
    yleclerc 1,547 on at
    RE: Remove option frmo editable grid in D365

    @Mayank Raval: Could you share your code? I tried to replicate it with my custom field but I get an error. JS validators send an error at line 24 - actions: [actionCollection]

    function preventOption(executionContext)

    {

    debugger;

    var executionEntity = (executionContext.getFormContext().data.entity);

    var statutField = executionEntity.attributes.getByName("new_statutdelatache");

    var statutValue = statutField.getValue();

    var field = statutField.controls.getByIndex(0);

    if(statutValue == 100000005 || statutValue == 100000008)

    {

    var actionCollection =

    {

    //message: 'Vous ne pouvez pas sélectionner cette valeur directement. Ces valeurs sont assignées via workflow seulement.'

    actions: null

    };

    actionCollection.actions = [function () {

    field.clearNotification('1');

    }];

    field.addNotification({

    messages: ['Vous ne pouvez pas sélectionner cette valeur directement. Ces valeurs sont assignées via workflow seulement.'],

    notificationLevel: 'ERROR',

    uniqueId: '1'

    actions: [actionCollection]

    });

    return false;

    }

    else

    {

    field.clearNotification(1);

    }

    }

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Remove option frmo editable grid in D365

    Hi All, 

    Since remove option from the option set field in editable grid is not available yet, We can go with another alternative like we can prevents user to select option and if user select same option then we can show ERROR notification message and prevent to save same record, Need to registered java script function on change event of the option set field.

    Please refer below screen:

    editableGrid_5F00_Test.png

    Thanks,

    Mayank Raval

    If found useful, please mark the answer as verified

  • gdas Profile Picture
    gdas 50,087 on at
    RE: Remove option frmo editable grid in D365

    Hello Shiva ,

    I have tried but its not working , I have posted it in  another thread . You can follow the thread .

    community.dynamics.com/.../279872

  • Shiva K Profile Picture
    Shiva K 40 on at
    RE: Remove option frmo editable grid in D365

    Hi Goutam,

    Did you found solution? to remove or Clear Options from Option Set in Editable Grid?

    Am also in same boat what to clear some options on Row Select Event.  :(

    Regards,

    Shiva K

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Remove option frmo editable grid in D365

    Sure Goutam,

    Thanks for quick reply.

  • Suggested answer
    gdas Profile Picture
    gdas 50,087 on at
    RE: Remove option frmo editable grid in D365

    Hi Nagarjuna,

    I have not tried yet ,could you please check the URL I have shared this is for both main and subgrid  , there is an event TAB , where you can registered your java script "OneRecordSelect" event.

    Hope this works.

    0488.editablegrid.png

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Remove option frmo editable grid in D365

    Hi Goutam,

    Thanks for the reply.

    But i'm working on home grid editables. so i need to remove ONE OPTION whenever i clicked on that column regardless of the condition. it should always to be removed.

    i can remove that option by going to entity customisztions, but it should be visible for existing records.

    how can we configure the javascript onload of home grid other than 1.record selection, 2.onchange, 3.onsave ?

    in below screen, the option Item3 should always be not visible when we click on that column to change.

    7848.Untitled.png

  • Suggested answer
    gdas Profile Picture
    gdas 50,087 on at
    RE: Remove option frmo editable grid in D365

    Hi Nagarzuna,

    Please check below reference point number 8 -

    docs.microsoft.com/.../make-grids-lists-editable-custom-control

    You need to write script onload event and remove the options from option set by below way -

    function OnloadOptionSet() {
        var optionSet = Xrm.Page.ui.controls.get("new_myoptionset");
        var optionSetValues = optionSet.getAttribute().getOptions();
        optionSet.clearOptions();
        optionSetValues.forEach(function (element) {
    
            if (element.value == "831260009" || element.value == "831260008")
                optionSet.addOption(element);
    
            if (element.value == "831260008" || element.value == "831260008")
                optionSet.addOption(element);
    
        });
    }


    Hope this helps.

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans