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

Notifications

Announcements

No record found.

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,983 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,983 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans