Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)
Suggested answer

Remove option frmo editable grid in D365

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,545 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,545 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,085 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,085 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,085 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

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

Featured topics

Product updates

Dynamics 365 release plans