Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Filter Lookup on Business Process Flow

Posted on by 57

Hi,

I have to filter a lookup on a Business Process Flow. I have used the code to filter on the lookup field Truck Sales Area. The code is triggered on on-Load. I Always get an error ff the stage where the lookup exists is not active. I want the code to be triggered once a specific stage named 'Add Company Details' is selected

function formonload() {
    preFilterTruckSalesArea();
}

function preFilterTruckSalesArea() {
    Xrm.Page.getControl("header_process_new_areaid").addPreSearch(function new_areaid() {
  var fetchXml = "<filter type='and'><condition attribute='new_areacode' operator='eq' value='1'/></filter>";     
        Xrm.Page.getControl("header_process_new_areaid").addCustomFilter(fetchXml);
    });
}

Any suggestions.

*This post is locked for comments

  • RE: Filter Lookup on Business Process Flow

    It is deeply annoying that there is:

    a. no non code means to do this

    b. no means to simply inherit the choices on the field if its on the form

    To me this is a glaring omission.

  • Verified answer
    Inogic Profile Picture
    Inogic 24,094 on at
    RE: Filter Lookup on Business Process Flow

    Hi Suyash,

    You can leverage the scripting capabilities on Business Process Flow and get your work done.

     

    Just to help you with the logic,

    • Register a script on Business Process Flow Stage Change.
    • Check the name of the current Stage.
    • If it’s the one you need, then let your logic flow or else do nothing.

     

    Below two links could help you,

     

    Hope this helps!

    Thanks!

  • Verified answer
    VermaNitin Profile Picture
    VermaNitin 455 on at
    RE: Filter Lookup on Business Process Flow

    Hi,

    You can use the following steps to achieve your requirement flawlessly.

    • Add event handler when a stage is selected on BPF using the function Xrm.Page.data.process.addOnStageSelected(callback).
    • Get the current stage of the BPF in the callback function using the Xrm.Page.data.process.getActiveStage() function like var activeStage = Xrm.Page.data.process.getActiveStage();
    • Check if the current stage of BPF is the stage where your lookup field is placed using the getName() function like var stageName = stageObj.getName(); 
    • Put your code to filter the lookup inside the if statement if (stageName =="Your Stage Name").


    Let me know if it 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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans