web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

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

(0) ShareShare
ReportReport
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);
        }
    });
}

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    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.

  • AneudysOrtiz Profile Picture
    5 on at

    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);
    
    }

  • cloflyMao Profile Picture
    25,210 on at

    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

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 151 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 134

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 55 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans