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

Plugin Error

$
0
0


I have now copied the entire code here below. I'm getting an error "Please contact microsoft support ...." on running the Workflow with custom workflow activity

public static DependencyProperty ContactProperty = DependencyProperty.Register("Contact", typeof(Lookup), typeof(CreateCarDetailsRecords));
        [CrmInput("Contact ID")]
        [CrmReferenceTarget("contact")]
        public Lookup Contact
        {
            get
            {
                return (Lookup)base.GetValue(ContactProperty);
            }
            set
            {

                base.SetValue(ContactProperty, value);
            }
        }

        public static DependencyProperty modelProperty = DependencyProperty.Register("model", typeof(CrmNumber), typeof(CreateCarDetailsRecords));
        [CrmInput("Model")]
        public CrmNumber model
        {

            get
            {
                return (CrmNumber)base.GetValue(modelProperty);
            }

            set
            {
                base.SetValue(modelProperty, value);
            }

        }

        private CrmNumber _marqueIndexValue;

        public CrmNumber MarqueIndexValue
        {
            get { return _marqueIndexValue; }
            set { _marqueIndexValue = value; }
        }



        public CreateCarDetailsRecords()
        {
            InitializeComponent();
        }

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            //local variables
            int marlen, marindex;

            string _model, _marque;
            _model = "";
            string[] _modelText = new string[6];

            // Get the context service.
            IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
            IWorkflowContext context = contextService.Context;

            // Use the context service to create an instance of CrmService.
            ICrmService crmService = context.CreateCrmService(true);



            RetrieveAttributeRequest modelRequest = new RetrieveAttributeRequest
            {
                EntityLogicalName = "cir_cardetails",
                LogicalName = "cir_model"
            };



            RetrieveAttributeResponse modelResponse = (RetrieveAttributeResponse)crmService.Execute(modelRequest);
            if (modelResponse != null)
            {
                var picklist = (PicklistAttributeMetadata)modelResponse.AttributeMetadata;



                int index, len, _modelvalue;

                len = picklist.Options.Length;

                _modelvalue=Convert.ToInt32(model.Value);

                for(index=0; index<len; index++)
                {
                    if(_modelvalue == index)
                    {
                         _model = picklist.Options[index].Label.ToString();
                        break;
                    }
                }


            }


            _modelText = _model.Split(' ');

            _marque = _modelText[0].ToString();

            RetrieveAttributeRequest marqueRequest = new RetrieveAttributeRequest
            {
                EntityLogicalName = "cir_cardetails",
                LogicalName = "cir_marque"
            };


            RetrieveAttributeResponse marqueResponse = (RetrieveAttributeResponse)crmService.Execute(marqueRequest);
            if (marqueResponse != null)
            {
                var marPicklist = (PicklistAttributeMetadata)modelResponse.AttributeMetadata;
                marlen = marPicklist.Options.Length;

                for (marindex = 0; marindex < marlen; marindex++)
                {
                    if (marPicklist.Options[marindex].Label.ToString() == _marque)
                    {
                        _marqueIndexValue = marPicklist.Options[marindex].Value;
                    }
                }

            }


            //Create an Car details which is linked to the contact record
            DynamicEntity cardetails = new DynamicEntity("cir_cardetails");

            cardetails["cir_carsdetailsid"] = Contact;

            //Setting the picklist value of Model
            Picklist modelPickList = new Picklist();
            modelPickList.Value = model.Value;
            cardetails.Properties.Add(new PicklistProperty("cir_model", modelPickList));

            //Setting the picklist value of Marque
            Picklist marquePickList = new Picklist();
            marquePickList.Value = MarqueIndexValue.Value;
            cardetails.Properties.Add(new PicklistProperty("cir_marque", marquePickList));

            Guid carkey = crmService.Create(cardetails);

            return ActivityExecutionStatus.Closed;
        }

The above OptionMetadata I didn't get on CRM 4.0 Custom workflow activity development. Don't know where I'm wrong in this when doing the code for CRM 4.0. So somehow I have managed to achieve this by doing the code like below but it seems the code not working for retrieving and then setting the pick-list value....

RetrieveAttributeRequest modelRequest = new RetrieveAttributeRequest
            {
                EntityLogicalName = "cir_cardetails",
                LogicalName = "cir_model"
            };



            RetrieveAttributeResponse modelResponse = (RetrieveAttributeResponse)crmService.Execute(modelRequest);
            if (modelResponse != null)
            {
                var picklist = (PicklistAttributeMetadata)modelResponse.AttributeMetadata;



                int index, len, _modelvalue;

                len = picklist.Options.Length;

                _modelvalue=Convert.ToInt32(model.Value);

                for(index=0; index<len; index++)
                {
                    if(_modelvalue == index)
                    {
                         _model = picklist.Options[index].Label.ToString();
                        break;
                    }
                }


            }


            _modelText = _model.Split(' ');

            _marque = _modelText[0].ToString();

            RetrieveAttributeRequest marqueRequest = new RetrieveAttributeRequest
            {
                EntityLogicalName = "cir_cardetails",
                LogicalName = "cir_marque"
            };


            RetrieveAttributeResponse marqueResponse = (RetrieveAttributeResponse)crmService.Execute(marqueRequest);
            if (marqueResponse != null)
            {
                var marPicklist = (PicklistAttributeMetadata)modelResponse.AttributeMetadata;
                marlen = marPicklist.Options.Length;

                for (marindex = 0; marindex < marlen; marindex++)
                {
                    if (marPicklist.Options[marindex].Label.ToString() == _marque)
                    {
                        _marqueIndexValue = marPicklist.Options[marindex].Value;
                    }
                }

            }


            //Create an Car details which is linked to the contact record
            DynamicEntity cardetails = new DynamicEntity("cir_cardetails");

            cardetails["cir_carsdetailsid"] = Contact;

            //Setting the picklist value of Model
            Picklist modelPickList = new Picklist();
            modelPickList.Value = model.Value;
            cardetails.Properties.Add(new PicklistProperty("cir_model", modelPickList));

            //Setting the picklist value of Marque
            Picklist marquePickList = new Picklist();
            marquePickList.Value = MarqueIndexValue.Value;
            cardetails.Properties.Add(new PicklistProperty("cir_marque", marquePickList));

            Guid carkey = crmService.Create(cardetails);

Can you please help

                                                                       

Viewing all articles
Browse latest Browse all 8223

Trending Articles