Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

Script error "System.NullReferenceException"

$
0
0

Hiii. i write just simple queryepression from the tutorial. The code looks like below:

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

namespace ClassLibrary4
{
    public class Class1 : IPlugin
    {
        public void Execute(IServiceProvider serviceprovider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceprovider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = (IOrganizationService)serviceprovider.GetService(typeof(IOrganizationService));
            
            if(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {

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

            if (entity.LogicalName != "new_callistyorder")
            return;

            if (context.MessageName.ToLower() == "update")
            {

                QueryExpression query = new QueryExpression { EntityName = "new_callistyorder", 
                    ColumnSet = new ColumnSet("new_nomororder") };
                EntityCollection colect = service.RetrieveMultiple(query);

                string str = string.Empty;
                foreach (Entity e in colect.Entities)
                {
                    str = str + e.Attributes["new_nomororder"].ToString();
                }
                throw new InvalidPluginExecutionException(str);

            }      
           
            }
        }
               
        
    }
    
}


After register this code to CRM. It give me error message like this:

Can anybody please tell me what wrong with those code and how can i fix this problem

Thanks


Viewing all articles
Browse latest Browse all 55831

Trending Articles



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