Community
Showing results for 
Search instead for 
Do you mean 
Reply

Retrieving Opportunity Field value - getting error upon retrieval of data - Operation is not valid due to the current state of the object.

Avid Listener
Posts: 44
Country: USA

Retrieving Opportunity Field value - getting error upon retrieval of data - Operation is not valid due to the current state of the object.

 OpportunityManager instance = new OpportunityManager(this.actApplication.ActFramework);
            Guid[] Guids = new Guid[1];
            Guids[0] = this.actApplication.ApplicationState.CurrentOpportunity.ID;

            Act.Shared.Collections.SortCriteria[] usortCriteria = null;
            OpportunityList uOList = default(OpportunityList);

          
            uOList = instance.GetOpportunities(Guids, usortCriteria);
         
            Act.Framework.ComponentModel.DBFieldDescriptor uField;
            string uFieldname;
            uFieldname = this.actApplication.ApplicationState.CurrentOpportunity.Fields.GetFieldNameFromAlias("No_Guests");
            uField = this.actApplication.ActFramework.GetFieldDescriptor(uFieldname, true);
            int uDfltGuestCount = (int)uField.GetValue(uOList[0]);
DBS
Avid Listener
Posts: 44
Country: USA

Re: Retrieving Opportunity Field value - getting error upon retrieval of data - Operation is not valid due to the current state of the object.

Solution:

 

Retrieve the MutibleEntryFieldDescriptor in a seperate class and return to method or calling function:

 

Below is the class

 

class Act_Findfunctions

{

 public static Act.Framework.MutableEntities.MutableEntityFieldDescriptor FindOppFieldDesriptor(string uAlias, Act.UI.ActApplication uActApp)
        {
            Act.Framework.MutableEntities.MutableEntityFieldDescriptor uRtn = null;
            uRtn = null;
            try
            {
                Act.Framework.MutableEntities.MutableEntityFieldDescriptor[] uFields = uActApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptors();
                Act.Framework.MutableEntities.MutableEntityFieldDescriptor uField;

                int x = 0;

                while (x < uFields.GetLength(0))
                {
                    uField = uFields[x];
                    if (uField.Alias == uAlias)
                    {
                        uRtn = uField;
                        x = uFields.GetLength(0);
                    }
                        x = x + 1;
                }
            }
            catch
            {
                // Do nothing
            }

            return uRtn;
        }
    }

 

Below is the code to retrieve the value from the field:

 

 try
            {
                OpportunityManager instance = new OpportunityManager(this.actApplication.ActFramework);
                Guid[] Guids = new Guid[1];
                Guids[0] = this.actApplication.ApplicationState.CurrentOpportunity.ID;

                Act.Shared.Collections.SortCriteria[] usortCriteria = null;
                OpportunityList uOList = default(OpportunityList);

                uOList = instance.GetOpportunities(Guids, usortCriteria);
                Act.Framework.MutableEntities.MutableEntityFieldDescriptor uField2;
              
                uField2 = ACT.DBS.BEO.Classes.Act_Findfunctions.FindOppFieldDesriptor("NO_Guests", this.actApplication);
                int uDfltGuestCount = (int)uField2.GetValue(uOList[0]);
                \\value in field 'NO_Guests" is returned as an integer to uDfltGuestcount

           }
            catch (Exception ex)
            {
                MessageBox.Show("Local Error := " + ex.Message);
            }

DBS