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

  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator 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
    25,208 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
    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
    28,981 Moderator 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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

#3
Sahra Profile Picture

Sahra 43

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans