Skip to main content

Notifications

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

Plugin to allow this option

Posted on by 365

pastedimage1604646271882v1.png

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace sample.sampl1
{
public class test : IPlugin
{
public object Service;

public Guid userId { get; private set; }

public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
Entity entity = (Entity)context.InputParameters["Target"];

//Entity Name

Entity userSetting = new Entity("usersettings");

//Guid Of the user record

userSetting.Id = userId;

//Attribute to set value of “Allow other Microsoft Dynamics 365 user to send email on your behalf”

userSetting["issendasallowed"] = true;

//Update the Record

Service.Update(userSetting);

}
}
}

i want to allow this option using plugin to trigger this email

  • unbeatable Profile Picture
    unbeatable 365 on at
    RE: Plugin to allow this option

    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Query;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Remoting.Services;
    using System.Text;
    using System.Threading.Tasks;

    namespace UpdateOpportunityProduct
    {
    public class UpdateOpportunityProduct : IPlugin
    {

    public void Execute(IServiceProvider serviceProvider)
    {
    //Obtain the execution context from the service provider.
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    if (context.MessageName != "Update")
    return;

    //Get a reference to the Organization service.

    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    IOrganizationService service = factory.CreateOrganizationService(context.UserId);

    //Extract the tracing service for use in debugging sandboxed plug-ins

    ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    //Entity Name

    Entity userSetting = new Entity("usersettings");

    //Guid Of the user record

    Guid userId = default(Guid);
    userSetting.Id = userId;

    //Attribute to set value of “Allow other Microsoft Dynamics 365 user to send email on your behalf”

    userSetting["issendasallowed"] = true;

    //Update the Record

    service.Update(userSetting);
    }
    }


    }

    above is my following code and I have built it and trying to register as a post image so that each time when the owner is changed, through plugin it automatically allows that option to send email

    pastedimage1604986655136v1.png

    pastedimage1604986655139v2.png

    I am not getting the option to register 

    [quote user="LA"]

    not a direct answer regarding plugin, btu just in case you were not aware, it is possible to set user personal settings via Power Automate / Flow.  (we do it for the users TimeZone as users are always created for us based on the Server and we are technically in a different timezone to the instances server).

    [/quote]
  • unbeatable Profile Picture
    unbeatable 365 on at
    RE: Plugin to allow this option

    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Query;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Remoting.Services;
    using System.Text;
    using System.Threading.Tasks;

    namespace UpdateOpportunityProduct
    {
    public class UpdateOpportunityProduct : IPlugin
    {

    public void Execute(IServiceProvider serviceProvider)
    {
    //Obtain the execution context from the service provider.
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    if (context.MessageName != "Update")
    return;

    //Get a reference to the Organization service.

    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    IOrganizationService service = factory.CreateOrganizationService(context.UserId);

    //Extract the tracing service for use in debugging sandboxed plug-ins

    ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    //Entity Name

    Entity userSetting = new Entity("usersettings");

    //Guid Of the user record

    Guid userId = default(Guid);
    userSetting.Id = userId;

    //Attribute to set value of “Allow other Microsoft Dynamics 365 user to send email on your behalf”

    userSetting["issendasallowed"] = true;

    //Update the Record

    service.Update(userSetting);
    }
    }


    }

    above is my following code and I have built it and trying to register as a post image so that each time when the owner is changed, through plugin it automatically allows that option to send email

    pastedimage1604986573964v2.png

    pastedimage1604986156772v1.png

    I am not getting the option to register 

  • Fubar Profile Picture
    Fubar 2,750 on at
    RE: Plugin to allow this option

    not a direct answer regarding plugin, btu just in case you were not aware, it is possible to set user personal settings via Power Automate / Flow.  (we do it for the users TimeZone as users are always created for us based on the Server and we are technically in a different timezone to the instances server).

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Plugin to allow this option

    It was a question. You registered your plugin already and as you mentioned "you getting an error". So in order to help you - help me, please provide the screenshot of the step registration and error that you get.

  • unbeatable Profile Picture
    unbeatable 365 on at
    RE: Plugin to allow this option

    can you please provide each and every step to register for this plugin

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Plugin to allow this option

    Can you please provide the screenshot that demonstrates step registration?

  • unbeatable Profile Picture
    unbeatable 365 on at
    RE: Plugin to allow this option

    while executing this code I am getting an error

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans