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
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
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]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
I am not getting the option to register
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).
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.
can you please provide each and every step to register for this plugin
Can you please provide the screenshot that demonstrates step registration?
while executing this code I am getting an error
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156