Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

formContext.getControl(arg).addNotification(notification): "Error loading control"

Posted on by 5

I was able to set a "recommendation" notification on my field as you can see on the left of the label on the first image and it works fine. But when actions are added, this error pops up and replaces the full field (Second image).

1.

pastedimage1584044105405v2.png

2.

pastedimage1584044357259v3.png

The error log shows "Cannot read property 'message' of undefined"

This is the code I'm using to generate the notification as per the documentation:

let temp: Function[] = null;
var actionCollection: Xrm.actionsObject = {
    message: "See duplicate contacts?",
    actions: temp
};

actionCollection.actions = [function () {
    console.log("works!");
}];

formContext.getControl("my_field").addNotification({
    messages: ["Title"],
    notificationLevel: "RECOMMENDATION",
    uniqueId: "potential_duplicate_contact",
    actions: actionCollection
});

I've tried multiple different variations of this code and always still the same error.

It seems like this feature is not completely done for the new UI? It also looks quite different from the old when it works. The documentation mentions it should show an "i" symbol and yet the symbol is a light-bulb. The icon is now on the left of the label instead of the field.

  • anonsgate Profile Picture
    anonsgate 420 on at
    RE: formContext.getControl(arg).addNotification(notification): "Error loading control"

    change

    actions: actionCollection

    to

    actions: [actionCollection]

  • Gabriel F Profile Picture
    Gabriel F 5 on at
    RE: formContext.getControl(arg).addNotification(notification): "Error loading control"

    I have tried this and the same error still appears. It was worth a shot.

  • Suggested answer
    Marco.P Profile Picture
    Marco.P 2,405 on at
    RE: formContext.getControl(arg).addNotification(notification): "Error loading control"

    I've just noted that in your code you miss the clearNotification, maybe that's why your error shows up when actions are added.

    try this

    actionCollection.actions = [function () {
        console.log("works!");

    formContext.getControl("my_field").clearNotification("potential_duplicate_contact");


    }];

  • Gabriel F Profile Picture
    Gabriel F 5 on at
    RE: formContext.getControl(arg).addNotification(notification): "Error loading control"

    Alright so there's some good news and some bad news. Good news is that recommendations on business rules work as they should. Bad news is that we require to fetch data from a related entity to make our recommendation, which you can't do with business rules.

    In the end I don't think we'll go with the recommendation route since the UI seems a bit awkward and not the most noticeable.

    Regardless of my decision, I still think this is something that should be looked at to make sure this is or isn't a bug that will need to be addressed.

    Gabriel

  • Gabriel F Profile Picture
    Gabriel F 5 on at
    RE: formContext.getControl(arg).addNotification(notification): "Error loading control"

    Thanks for the quick response Marco. I will try the business rule as you have suggested and will get back to you after.

  • Marco.P Profile Picture
    Marco.P 2,405 on at
    RE: formContext.getControl(arg).addNotification(notification): "Error loading control"

    Hi,

    i will dig deep into this (and test the js code), in the meantime i can suggest you to try to achieve the same result with a business rule

    (wich i already used for case like this with no issue at all)

    https://community.dynamics.com/crm/b/magnetismsolutionscrmblog/posts/how-to-use-recommendations-in-dynamics-365-business-rules

    I think it's Worth a try !

    Marco

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