Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)

Posted on by Microsoft Employee

Hey guys,

I am currently working on a requirement regarding the Business Process Flow in the new Unified Interface.
I need to add a custom view I create with JavaScript to a lookup field in the BPF.

So in JS, I create a custom FetchXML for the filtering and also create custom FetchXML for the layout.
Once I got both get the control via the formContext and add the custom view.
So far so good: The view is added to the list of views when I click on "Change View" on the lookup in the BPF.
But unfortunately it is not applied by default, so a user wouldn't need to click on "Change View".

I have tried to use the "setDefaultView" function right after I add the custom view but unfortunately that does not work.
It worked a couple of weeks ago actually only by using the "addCustomView" function but now it does not set it to default anymore.

Does anyone experience the same issue or came across something familiar?

Here is my code:

//Create FetchXML and GridXML for CustomView in BPF
 var consultantFetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>"+
        "<entity name='systemuser'>"+
          "<attribute name='fullname' />"+
          "<attribute name='systemuserid' />"+
          "<order attribute='fullname' descending='false' />"+
          "<link-entity name='teammembership' from='systemuserid' to='systemuserid' visible='false' intersect='true'>"+
            "<link-entity name='team' from='teamid' to='teamid' alias='ad'>"+
              "<filter type='and'>"+
                "<condition attribute='teamid' operator='eq' uiname='Consulting' uitype='team' value='{269FDEA7-EAF0-E911-A812-000D3AB958AA}' />"+
              "</filter>"+
            "</link-entity>"+
          "</link-entity>"+
        "</entity>"+
      "</fetch>";
//Create custom FetchXML for the layout
 var consultantLayout = "<grid name='resultset' jump='fullname' select='1' icon='1' preview='1'>"+
                   "<row name='result' id='systemuserid'>"+
                     "<cell name='fullname' width='300' />"+
                   "</row>"+
                 "</grid>";
//Add the custom view to the control
 formContext.getControl("header_process_new_consultant").addCustomView("{00000000-0000-0000-0000-000000000002}", "systemuser", "Consultant View", consultantFetch, consultantLayout, true);
//Try to set the view default
 formContext.getControl("header_process_new_consultant").setDefaultView("{00000000-0000-0000-0000-000000000002}");
  • Mr.Lin Profile Picture
    Mr.Lin 20 on at
    RE: Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)
    [quote user="Bharat Premji"]

    Hi Erik,

    Im using the following JavaScript to set the default view:

    formContext.getControl(lookup).setDefaultView(viewGUID)

    where lookup is the name of the field in the BPF, in the following format: header_process_xxx_yyyyyy and the viewGUID is the GUID of the view I want to show.  

    I don't seem to get any problems with the show recently used items, it simply shows the records in the view.  I dont use the .addCustomView method

    Regards

    Bharat

    [/quote]

    Hello, I need to  hide "Change View" button. Is there a way to do this?

    If can't hide the button,I would like to know after set the default view by the way you did whether the user can switch to another view?

    Looking forward to your reply,Thx

  • Erik Schaap Profile Picture
    Erik Schaap 25 on at
    RE: Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)

    I am using the same Javascript method. So I followed the suggestion from Microsoft you shared above; I removed the fields from the BPF, saved it and re-added the fields. And now the recent used items are not showed anymore in the BPF lookup fields.

    Thx!

  • BharatPremji Profile Picture
    BharatPremji 2,485 on at
    RE: Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)

    Hi Erik,

    Im using the following JavaScript to set the default view:

    formContext.getControl(lookup).setDefaultView(viewGUID)

    where lookup is the name of the field in the BPF, in the following format: header_process_xxx_yyyyyy and the viewGUID is the GUID of the view I want to show.  

    I don't seem to get any problems with the show recently used items, it simply shows the records in the view.  I dont use the .addCustomView method

    Regards

    Bharat

  • Erik Schaap Profile Picture
    Erik Schaap 25 on at
    RE: Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)

    Thanks for the update on this topic Bharat! Indeed it seems to be working again after this update.

    Now the default view can be set (again) on lookup in the BPF, it still shows the recently used items in the field in the BPF although this setting is turned off in the field properties on the form.

    Do you or anyone else have a suggestion on how to turn 'show recently used items' off in a lookup in the BPF? I cannot find any javascript method to do so.

  • BharatPremji Profile Picture
    BharatPremji 2,485 on at
    RE: Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)

    So Microsoft have come back after looking at the issue and suggested a few fixes:

    • Re-create the BPF and don't have any special characters in the Name of the stage (I added a full stop into my stage name)
    • Remove the field from the BPF, save it and then re-add the field.

    However I have logged back into my Sandbox environment this morning and the filtering seems to be working again without have to make any changes.  I did notice the version of my instance has been updated to:

    2020_2D00_02_2D00_07_5F00_6_2D00_52_2D00_49.png

    Hope this helps you guys

    Bharat

  • BharatPremji Profile Picture
    BharatPremji 2,485 on at
    RE: Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)

    Hi,

    I have managed to replicate the issue and log a ticket with Microsoft.

    The filtering seems to work unless you deactivate the BPF and then turn it back on.  The filtering will work in the old UI but not the unified interface.

    The version of Dynamics I am on is:

    2020_2D00_01_2D00_29_5F00_6_2D00_42_2D00_50.png

    I'll update the thread once I have a reply back from Microsoft

    Regards

    Bharat

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)

    Hey Bharat,

    sorry for the delayed response.

    Unfortunately I have no solution to this issue and could not file a proper Ticket to MS since the customers instance I had this issue on had no support contract with Microsoft at that moment.

    I solved the issue for this customer with a workaround adjusting the filtering on the default lookup view for the entity I needed it on.

    Maybe somebody else has come across a similar issue and already had the chance to talk to Microsoft about it?

  • BharatPremji Profile Picture
    BharatPremji 2,485 on at
    RE: Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)

    Hi,

    I've come across a similar problem today.  

    My scenario is that we have some JavaScript that filters a lookup which was working up until today.  I deactivated the Business Process Flow and reactivated it and now the filtering has stopped working.

    We have an environment where I haven't deactivated the BPF and the filtering is still working in that one with the same JavaScript

    Did you get a response from Microsoft as to if this is a bug on their end?

    Regards

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)

    @Ajyendra

    I've adjusted the code and applied it onto a lookup on the form and it works perfectly as anticipated. So it only does not work in the Business Process Flow. I guess I will need to raise a ticket to Microsoft Support.

    Thanks for advice.

  • Verified answer
    ajyendra Profile Picture
    ajyendra 1,730 on at
    RE: Set custom view as default for lookup in Business Process Flow via JavaScript (Unified Interface)

    Put the field to your form not in BPF  then check the code work for not . If it still not working then might be not an issue of BFP . It might be issue of addcustomfunction. If issue persist even when lookup field is in form then

    Raise a ticket to Microsoft Support . It might be mistake from their end.

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans