Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Object reference not set to an instance of an object, when calling a custom action to send email notification

Posted on by 62

Hello everyone, 

I am posting this question with a desperate need of help,

And to give you some context, we have a custom Action that sends email notifications and I have a plugin that calls that custom action and sends email notification.

It works when called from an administrator user and at top of Organization, but when I try to execute it from a different user from a child BU with different priviledges, I get the error. "Object reference not set to an instance of an object".

That 2nd user has still access to the parameters needed to send the notification, notification config ref, ent. logical and ID ( Regarding Case )

Any ideias what might be causing this, please?

Logs from plugin:

Custom Action:

pastedimage1658751102499v1.png

Plugin Calling the action: 

      try
            {
                OrganizationRequest req = new OrganizationRequest("noesis_NotifyOnDemand");

                req["Target"] = notificationConfigRef;
                req["NotificationConfiguration"] = notificationConfigRef;
                req["EntityLogicalName"] = targetEntityReference.LogicalName;
                req["EntityId"] = targetEntityReference.Id.ToString();
                req["CreateAsDraft"] = createAsDraft;
                req["SplitToRecipients"] = splitToRecipients;

                TracingService.Trace($"Requesting Notification...\nParameters: {JsonConvert.SerializeObject(req.Parameters)}");

                OrganizationResponse response = Dynamics365Context.Execute(req);

                return response;
            }
            catch (Exception ex)
            {
                TracingService.Trace($"***Exception*** - Requesting Notification... Message: {ex.Message}, InnerException: {ex.InnerException}");
                throw new InvalidPluginExecutionException($"Exc. Message: {ex.Message}"); 
            }

Successfull Call

Target: incident | 818f1d1e-b10b-ed11-b822-00155d20085f

Service Provider not null

Plugin Execution Context not null

Organization Service Factory not null

Organization Service not null

IncidentManager is null? : False

PreImage is null? : False

START -- CheckAndExecuteCaseTypeOptions

Case Type Config: ebf093f8-15e8-ec11-b853-00155da304b1

Returned Case Type Options count: 7

SKIP -- Case Status != CTO Status: WaitingforInfo != Open? True

SKIP -- Case Status != CTO Status: WaitingforInfo != WorkInProgress? True

Found a CTO with matching status reason : WaitingforInfo and with Notification Configuration [Case Flow] - Notificações SmartPOS d601ba5e-12e8-ec11-b853-00155da304b1

Requesting Notification...

Parameters: [{"Key":"Target","Value":{"Id":"d601ba5e-12e8-ec11-b853-00155da304b1","LogicalName":"noesis_notificationconfiguration","Name":"[Case Flow] - Notificações SmartPOS","KeyAttributes":[],"RowVersion":null}},{"Key":"NotificationConfiguration","Value":{"Id":"d601ba5e-12e8-ec11-b853-00155da304b1","LogicalName":"noesis_notificationconfiguration","Name":"[Case Flow] - Notificações SmartPOS","KeyAttributes":[],"RowVersion":null}},{"Key":"EntityLogicalName","Value":"incident"},{"Key":"EntityId","Value":"818f1d1e-b10b-ed11-b822-00155d20085f"},{"Key":"CreateAsDraft","Value":false},{"Key":"SplitToRecipients","Value":false}]

Notification was sent successfully. ActivityIds a9bbc067-0b0c-ed11-b822-00155d20085f

END -- CheckAndExecuteCaseTypeOptions -- END

ERROR LOG

Target: incident | 818f1d1e-b10b-ed11-b822-00155d20085f

Service Provider not null

Plugin Execution Context not null

Organization Service Factory not null

Organization Service not null

IncidentManager is null? : False

PreImage is null? : False

START -- CheckAndExecuteCaseTypeOptions

Case Type Config: ebf093f8-15e8-ec11-b853-00155da304b1

Returned Case Type Options count: 7

SKIP -- Case Status != CTO Status: Pendingthirdparties != Open? True

SKIP -- Case Status != CTO Status: Pendingthirdparties != WorkInProgress? True

SKIP -- Case Status != CTO Status: Pendingthirdparties != WaitingforInfo? True

Found a CTO with matching status reason : Pendingthirdparties and with Notification Configuration [Case Flow] - Notificações SmartPOS d601ba5e-12e8-ec11-b853-00155da304b1

Requesting Notification...

Parameters: [{"Key":"Target","Value":{"Id":"d601ba5e-12e8-ec11-b853-00155da304b1","LogicalName":"noesis_notificationconfiguration","Name":"[Case Flow] - Notificações SmartPOS","KeyAttributes":[],"RowVersion":null}},{"Key":"NotificationConfiguration","Value":{"Id":"d601ba5e-12e8-ec11-b853-00155da304b1","LogicalName":"noesis_notificationconfiguration","Name":"[Case Flow] - Notificações SmartPOS","KeyAttributes":[],"RowVersion":null}},{"Key":"EntityLogicalName","Value":"incident"},{"Key":"EntityId","Value":"818f1d1e-b10b-ed11-b822-00155d20085f"},{"Key":"CreateAsDraft","Value":false},{"Key":"SplitToRecipients","Value":false}]

***Exception*** - Requesting Notification... Message: Object reference not set to an instance of an object., InnerException:

Thank you, 

Best regards

  • Verified answer
    T1sh0 Profile Picture
    T1sh0 62 on at
    RE: Object reference not set to an instance of an object, when calling a custom action to send email notification

    Thank you all for the suggestions. I have found out that this user was missing ReadAccess on Mailbox entity and therefore the plugin that sends notification returned "Object reference not set to an instance of an object." when trying to find the mailbox

  • Guido Preite Profile Picture
    Guido Preite 54,065 Moderator on at
    RE: Object reference not set to an instance of an object, when calling a custom action to send email notification

    probably is the action itself that generate the exception, not the code you wrote to call the action.

    You should check inside the action code if there are some custom activities called and the code there

    hope it helps

  • a33ik Profile Picture
    a33ik 84,321 Most Valuable Professional on at
    RE: Object reference not set to an instance of an object, when calling a custom action to send email notification

    Hello,

    Do you have a plugin that handles your noesis_NotifyOnDemand message?

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,645 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans