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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Filter customerid field to show only Accounts

(0) ShareShare
ReportReport
Posted on by 15

Hi All,

Within the 'Invoice' form, I'm attempting to add a JScript to filter the 'customerid' field to only show Accounts.

I've been following similar coding to the one found here:
https://community.dynamics.com/365/b/dynamics365enterprisecloudfronts/posts/filter-customer-type-field-to-display-only-accounts-in-d365-v9-0-using-javascript

However when I go to create an Invoice, I get a Script Error on load saying "One of the scripts for this record has caused an error. For more details, download the log file." 

Upon investigating the file, the first line states "Web resource method does not exist"

Any ideas as to why it doesn't believe the resource exists?

Thanks in advance,
Michael

I have the same question (0)
  • zica Profile Picture
    on at
    RE: Filter customerid field to show only Accounts

    You may also try the new Client API form context

    docs.microsoft.com/.../clientapi-form-context

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Filter customerid field to show only Accounts

    Michael,

    In order to solve your issue in Handler Properties screen set "Function" to oInvoiceFormCustomization.setCustomerLookupToShowAccount, then save, publish and test.

  • MichaelHoward Profile Picture
    15 on at
    RE: Filter customerid field to show only Accounts

    Hi Andrew,

    Below is the code I've used (slightly altered to match our environment where the field is 'customerid' rather than 'parentcustomerid' etc):

    ___________________________________________________________

    var oInvoiceFormCustomization = {

    setCustomerLookupToShowAccount: function (execContext) {

    var formContext = execContext.getFormContext();

    if (formContext.getControl("customerid")) {

    var account = formContext.getControl('customerid');

    if (account.getEntityTypes().length > 1) {

    account.setEntityTypes(['account']);

    }

    }

    }};

    ____________________________________________________

    The Handler Properties are below:

    pastedimage1582706672199v1.png

    Many thanks,

    Michael

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Filter customerid field to show only Accounts

    Michael,

    Can you please provide a screenshot that demonstrates how you registered your onload event handler and confirm that code you used is 1 to 1 equal to the code from the article?

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
DAnny3211 Profile Picture

DAnny3211 136

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 130

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans