Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

OptionSet removeOption() doesn't work for business process field

Posted on by 5

I'm trying to remove some options from an optionSet inside the BPF, but it doesn't work. It only works for fields inside the form.

function cargarRazonesDevolucion(executionContext) {
    const form = executionContext.getFormContext();
    const headerControl = form.getControl('header_process_ao_razon_devolucion_seleccion');
    if (!headerControl)
        return;

    const control = form.getAttribute('ao_razon_devolucion_seleccion');

    const options = control.getOptions();
    console.log("OPTIONS", options);

    let caseType = form.getControl('ao_tipo_caso').getAttribute().getValue()[0].name;
    console.log("CASETYPE", caseType);

    options.forEach(item => {
        if (caseType == 'SOLICITUD' && item.text.includes('reclamo')) {
            headerControl.removeOption(item.value);
        } else if (caseType == 'RECLAMACION' && item.text.includes('solicitud')) {
            headerControl.removeOption(item.value);
        }
    });
}

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: OptionSet removeOption() doesn't work for business process field

    Hi,

    Can you try removing custom control configuration for this field and see if it works. This way we can say that it is not working when we add custom control to the field.

    BTW are you using your own custom control or OOB custom control provided by microsoft?

    If found helpful, Please mark my answer verified.

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: OptionSet removeOption() doesn't work for business process field

    Hi Aneudys,

    I have tested the code, it can work for BPF.

    function cargarRazonesDevolucion(executionContext) {
     const form = executionContext.getFormContext();
     const headerControl = form.getControl('header_process_purchasetimeframe');
     if (!headerControl)
      return;
     headerControl.removeOption(1);
    }

    Before:

    3683.png

    After:

    04783.png

    So you can check that the Name of field that you want to modify and the value that you want to remove from the option set Whether is correct. Or you can debug your JS code to find why it can not work.

    5383.png

    Regards,

    Clofly

  • AneudysOrtiz Profile Picture
    AneudysOrtiz 5 on at
    RE: OptionSet removeOption() doesn't work for business process field

    Hello. Thanks for your answer.

    I tried exactly the same way you did, but it doesn't work.

    BTW the condition works well and it reaches to execute the removeOption function but Idk if it fails because of custom controls.

    function cargarRazonesDevolucion(executionContext) {
    
        const form = executionContext.getFormContext();
        const headerControl = form.getControl('header_process_ao_razon_devolucion_seleccion');
     if (!headerControl)
           return;
    
       headerControl.removeOption(100000000);
    
    }

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: OptionSet removeOption() doesn't work for business process field

    Hi,

    I have just tried below code on Lead for OOB Lead Source field and it worked.

    function cargarRazonesDevolucion(executionContext) {

       const form = executionContext.getFormContext();

    const headerControl = form.getControl('header_process_leadsourcecode');

       if (!headerControl)

           return;

    headerControl.removeOption(930720003);

    }

    Please check below conditions in your code. Add alert inside condition and see it it is going inside.

    I suspect there is something wrong with the condition.

    if (caseType == 'SOLICITUD' && item.text.includes('reclamo')) {

               headerControl.removeOption(item.value);

           } else if (caseType == 'RECLAMACION' && item.text.includes('solicitud')) {

               headerControl.removeOption(item.value);

           }

    If found helpful, Please mark my answer verified.

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Liquid error: parsing "/forums/thread/details/?threadid=ddbee98e-04af-4689-a596-6e8bb0d4e80b%27nvOpzp;%20AND%201=1%20OR%20(%3C%27%22%3EiKO))," - Too many )'s.