Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Plugin query

$
0
0

Hi All,

I want to generate the unique id using plugin and concatenate it with the location  code. this location code is coming from another entity which has relation. I wrote the code for generating series number , but now I want your help how to get the value of the related entity field . please find the below code and give me the code which suits the above requirement.

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

autonumbergen

{

   

publicclassClass1:IPlugin


    {

       

publicvoidExecute(IServiceProviderserviceProvider)

        {

           

IPluginExecutionContextcontext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

           

IOrganizationServiceFactoryserviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

           

IOrganizationServiceservice = serviceFactory.CreateOrganizationService(context.UserId);

           

//  IOrganizationService ServiceProxy = ServiceProxy


           

if(context.InputParameters.Contains("Target")&& context.InputParameters["Target"]isEntity)

            {

               

Entityentity = (Entity)context.InputParameters["Target"];

               

QueryExpressionquery =newQueryExpression("msjps_incidentreport");

                query.ColumnSet =

newColumnSet(true);

               

EntityCollectionresult = service.RetrieveMultiple(query);

 

               

inttotalRecords = result.Entities.Count;

               

//string final = totalRecords.ToString();


               

//string total = Convert.ToString(totalRecords);


               

intfinal = totalRecords + 1;

                entity.Attributes[

"msjps_trackingnumber"] =Convert.ToString(final);

            }

        }

    }

}


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>