Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

CRM 2016: Error CS0103: The name 'item' does not exist in the current context

Avatar of apollo7
apollo7Flag for United States of America asked on
.NET ProgrammingC#* Dynamics CRM
14 Comments1 Solution645 ViewsLast Modified:
I am working on C# development for a CRM 2016 on premise project.  The solution includes classes, plugins, workflows and unit test projects.  

The problem I am having is with code taken from the Order class (which is working) that submits information to a mainframe for paint colors.  

I want to replicate the Order code in the Change Order class.  Most of the Order code copies over to the Change Order class without error,  but I am getting the "Error CS0103: The name 'item' does not exist in the current context" message for 6 lines of code.

I  have tried adding a Using statement, adding a reference, reviewing Stack Overflow suggestions but so far no success in clearing the errors.

I have included the Order class code (working version) and the Change Order code (with errors) below.  I have added comments (//ERROR ON LINE BELOW)  to the 6 lines of Change Order code where I getting the error on the 'item' reference

This is urgent and I am open to online sessions if that is required.

Thank you

ORDER CLASS CODE (NO ERRORS)
                     
#region Paint 
                            string paintCategory = item.GetAttributeValue<string>("uxce_category");
                              //1
                                string NarrativePaintColor = item.GetAttributeValue<string>("uxce_paintcolorselectionnarr");
                                if (!String.IsNullOrEmpty(NarrativePaintColor))
                                {
                                    //Remove trailing ';'
                                    if (NarrativePaintColor.EndsWith(";"))
                                    {
                                        NarrativePaintColor = NarrativePaintColor.Substring(0, NarrativePaintColor.Length - 1);
                                    }
                                    var results = nb.GeneratePaintNarrativeArray(NarrativePaintColor);

                                    //loop through each array item and apply the narrative code/desc
                                    for (int a = 0; a < results.Length; a++)
                                    {
                                        nb.AddNarrative(results[a][0], "N", results[a][1]);
                                    }
                                }
                                //2
                                string NarrativePaintDesign = item.GetAttributeValue<string>("uxce_paintcolorselectionnarr");
                                if (!String.IsNullOrEmpty(NarrativePaintDesign))
                                {
                                    string productdesc = item.GetAttributeValue<string>("productdescription");
                                    string optionCd = item.GetAttributeValue<string>("uxce_salesoption");

                                if (!String.IsNullOrEmpty(paintCategory) && paintCategory == "Paint Design")
                                {
                                    if (divisionCode == "K")
                                    {
                                        if (productdesc.Contains("Spectrum"))
                                        {
                                            nb.AddNarrative("1", "P", "SPECTRUM DESIGN CODE: " + optionCd);
                                            nb.AddNarrative("2", "P", "SPECTRUM DESIGN CODE: " + optionCd);
                                        }
                                        else
                                        {
                                            nb.AddNarrative("1", "P", "DESIGN CODE: " + optionCd);
                                            nb.AddNarrative("2", "P", "DESIGN CODE: " + optionCd);
                                        }
                                    }

                                    else if (divisionCode == "P")
                                    {
                                        if (productdesc.Contains("Feature"))
                                        {
                                            nb.AddNarrative("1", "P", "FEATURE DESIGN CODE: " + optionCd);
                                            nb.AddNarrative("2", "P", "FEATURE DESIGN CODE: " + optionCd);
                                        }
                                        else
                                        {
                                            nb.AddNarrative("1", "P", "CUSTOM DESIGN CODE: " + optionCd);
                                            nb.AddNarrative("2", "P", "CUSTOM DESIGN CODE: " + optionCd);
                                        }
                                    }
                                }
                                   
                                }

                                //#3
                                string NarrativePaintSpec = item.GetAttributeValue<string>("uxce_paintspecificationsnarr");
                                if (!String.IsNullOrEmpty(NarrativePaintSpec))
                                {                         
                                    if (NarrativePaintSpec.EndsWith(";"))
                                    {
                                        NarrativePaintSpec = NarrativePaintSpec.Substring(0, NarrativePaintSpec.Length - 1);
                                    }
                                    string[] SpecResults = NarrativePaintSpec.Split(';');
                                    char c1 = 'A';
                                    //loop through each array item and apply the narrative code/desc
                                    for (int a = 0; a < SpecResults.Length; a++)
                                    {
                                        nb.AddNarrative(c1.ToString(), "P", SpecResults[a]);
                                        c1++;

                                    }
                                
                            }
                            #endregion

CHANGE ORDER CODE (ERRORS)

       #region Paint
                    
                    //ERROR ON LINE BELOW
                    string paintCategory = item.GetAttributeValue<string>("uxce_category");

                    //1
                    //ERROR ON LINE BELOW
                   string NarrativePaintColor = item.GetAttributeValue<string>("uxce_paintcolorselectionnarr");
                    if (!String.IsNullOrEmpty(NarrativePaintColor))
                    {
                        //Remove trailing ';'
                        if (NarrativePaintColor.EndsWith(";"))
                        {
                            NarrativePaintColor = NarrativePaintColor.Substring(0, NarrativePaintColor.Length - 1);
                        }


                        var results = nb.GeneratePaintNarrativeArray(NarrativePaintColor);

                        //loop through each array item and apply the narrative code/desc
                        for (int a = 0; a < results.Length; a++)
                        {
                            nb.AddNarrative(results[a][0], "N", results[a][1]);

                        }
                    }
                    //2
                    //ERROR ON LINE BELOW
                    string NarrativePaintDesign = item.GetAttributeValue<string>("uxce_paintcolorselectionnarr");
                    if (!String.IsNullOrEmpty(NarrativePaintDesign))
                    {   
                    //ERROR ON LINE BELOW
                     string productdesc = item.GetAttributeValue<string>("productdescription");
                    //ERROR ON LINE BELOW
                      string optionCd = item.GetAttributeValue<string>("uxce_salesoption");

                        if (!String.IsNullOrEmpty(paintCategory) && paintCategory == "Paint Design")
                        {

                            if (divisionCode == "K")
                            {

                                if (productdesc.Contains("Spectrum"))
                                {
                                    nb.AddNarrative("1", "P", "SPECTRUM DESIGN CODE: " + optionCd);
                                    nb.AddNarrative("2", "P", "SPECTRUM DESIGN CODE: " + optionCd);
                                }
                                else
                                {
                                    nb.AddNarrative("1", "P", "DESIGN CODE: " + optionCd);
                                    nb.AddNarrative("2", "P", "DESIGN CODE: " + optionCd);
                                }
                            }

                            else if (divisionCode == "P")
                            {
                                if (productdesc.Contains("Feature"))
                                {
                                    nb.AddNarrative("1", "P", "FEATURE DESIGN CODE: " + optionCd);
                                    nb.AddNarrative("2", "P", "FEATURE DESIGN CODE: " + optionCd);
                                }
                                else
                                {
                                    nb.AddNarrative("1", "P", "CUSTOM DESIGN CODE: " + optionCd);
                                    nb.AddNarrative("2", "P", "CUSTOM DESIGN CODE: " + optionCd);
                                }
                            }
                        }


                    }

                    //#3
                    //ERROR ON LINE BELOW
                    string NarrativePaintSpec = item.GetAttributeValue<string>("uxce_paintspecificationsnarr");