I wrote a plugin to do what i need and registered it . After that point how can i use it in this page? I show my code below which is in the plugin. Especially i do not know if i wrote correct code. When user selects more than one firm;after save(kaydet) button press, the records wiil be saved to the database table one row after another. Only the guid of the firm will change, The other infos are the same. I mean if 3 firms selected from the checkboxes. 3 rows with different guids of firm are saved to the database table with same infos(fatura no, marka etc.)
Can you help me about these. I wrote my firs plugin and will use in crm form. I have to to this because the future of my job belongs to this.
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 CheckboxMagazaKaydet
{
public class MyPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
if ("Create,Update".Contains(context.MessageName) == false) return;
if (!context.InputParameters.Contains("Target") || (context.InputParameters["Target"] is Entity) == false) return;
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "new_destek_yerelreklam_detay") return;
try
{
var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = factory.CreateOrganizationService(context.UserId);
if (context.InputParameters != null)
{
Entity reklamentity = new Entity("new_destek_yerelreklam_detay");
if (reklamentity.Attributes.Contains("new_magaza"))
{
Money tutar = (Money)reklamentity.Attributes["new_tutar"];
int faturano = (int)reklamentity.Attributes["new_faturano"];
DateTime faturatarihi = (DateTime)reklamentity.Attributes["new_faturatarihi"];
string donem = (string)reklamentity.Attributes["new_donem"];
int marka = (int)reklamentity.Attributes["new_marka"];
reklamentity.Attributes["new_tutar"] = tutar;
reklamentity.Attributes["new_faturano"] = faturano;
reklamentity.Attributes["new_faturatarihi"] = faturatarihi;
reklamentity.Attributes["new_donem"] = donem;
reklamentity.Attributes["new_marka"] = marka;
//Update
service.Update(reklamentity);
}
else
{
Guid magazaId = (reklamentity["new_magaza"] as EntityReference).Id;
Money tutar = (Money)reklamentity.Attributes["new_tutar"];
int faturano = (int)reklamentity.Attributes["new_faturano"];
DateTime faturatarihi = (DateTime)reklamentity.Attributes["new_faturatarihi"];
string donem = (string)reklamentity.Attributes["new_donem"];
int marka = (int)reklamentity.Attributes["new_marka"];
reklamentity.Attributes["new_tutar"] = tutar;
reklamentity.Attributes["new_faturano"] = faturano;
reklamentity.Attributes["new_faturatarihi"] = faturatarihi;
reklamentity.Attributes["new_donem"] = donem;
reklamentity.Attributes["new_marka"] = marka;
service.Create(reklamentity);
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(string.Format("ERROR:message:{0}", ex.InnerException != null ? ex.InnerException.Message : ex.Message));
}
}
}
}