/// <summary>
        /// Tests a call to Opportunity Service
        /// </summary>
        static void TestOpportunityService()
        {
            Console.WriteLine("TestOpportunityService");
            System.ServiceModel.Channels.Binding binding      = FaBindingFactory.GetUsernameTokenOverSslBinding();
            EndpointAddress          endpointAddress          = new EndpointAddress(new Uri("Url to the service"));
            OpportunityServiceClient opportunityServiceClient = FaServiceFactory.GetOpportunityServiceClient(binding, endpointAddress, new NetworkCredential(userName, password));

            FusionApplicationAccelerator.OpportunityServiceReference.FindCriteria findCriteria = new FusionApplicationAccelerator.OpportunityServiceReference.FindCriteria();
            findCriteria.fetchSize  = 2;
            findCriteria.fetchStart = 0;

            string[] findAttributes = new string[2] {
                "OptyId", "CustomerAccountId"
            };
            findCriteria.findAttribute = findAttributes;

            FusionApplicationAccelerator.OpportunityServiceReference.FindControl findControl = new FusionApplicationAccelerator.OpportunityServiceReference.FindControl();
            Opportunity[] result = opportunityServiceClient.findOpportunity(findCriteria, findControl);
            if (null != result && result.Length > 0)
            {
                foreach (Opportunity opportunity in result)
                {
                    Console.WriteLine("  OptyId = " + opportunity.OptyId);
                }
            }
            else
            {
                if (null == result)
                {
                    Console.WriteLine("  result null ");
                }
                else
                {
                    Console.WriteLine("  result empty ");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Find open opportunities based on contact or org.
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public List <OpportunityModel> FindOpenOpportunities(string attribute, string value)
        {
            try
            {
                ViewCriteriaItem item = new ViewCriteriaItem();
                item.upperCaseCompare = false;
                item.attribute        = attribute;
                item.@operator        = "=";
                item.Items            = new[] { value };

                ViewCriteriaItem item2 = new ViewCriteriaItem();
                item2.upperCaseCompare = true;
                item2.attribute        = "StatusCode";
                item2.@operator        = "=";
                item2.Items            = new[] { "Open" };

                ViewCriteriaRow condition1 = new ViewCriteriaRow();
                condition1.upperCaseCompare = false;
                condition1.item             = new[] { item, item2 };

                ViewCriteria viewCriteria = new ViewCriteria();
                viewCriteria.conjunction = Conjunction.And;
                viewCriteria.group       = new[] { condition1 };

                //Sorting by Creation date.
                SortAttribute sortAttr = new SortAttribute();
                sortAttr.name       = "CreationDate";
                sortAttr.descending = true;

                FindCriteria findCriteria = new FindCriteria();
                findCriteria.fetchStart = 0;
                findCriteria.fetchSize  = 500;
                findCriteria.filter     = viewCriteria;
                findCriteria.sortOrder  = new[] { sortAttr };

                findCriteria.findAttribute = new string[]
                {
                    "KeyContactId",
                    "PrimaryContactPartyName",
                    "SalesAccountId",
                    "TargetPartyName",
                    "OptyId",
                    "OptyNumber",
                    "PartyName1",
                    "EmailAddress",
                    "Name",
                    "Description",
                    "StatusCode",
                    "SalesMethod",
                    "SalesStage",
                    "SalesChannelCd",
                    "CurrencyCode",
                    "Revenue",
                    "WinProb",
                    "CreatedBy",
                    "CreationDate",
                    "EffectiveDate"
                };

                FindControl findControl = new FindControl();

                Opportunity[] opp = _opportunityClient.findOpportunity(findCriteria, findControl);

                return(getOpportunityModels(opp));
            }
            catch (EndpointNotFoundException wex)
            {
                //Handling incorrect opportunity endpoint
                _logger.Error(wex.Message, wex.StackTrace);
                MessageBox.Show(OSCExceptionMessages.EndpointNotFound,
                                OSCOpportunitiesCommon.EndpointNotFound, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (MessageSecurityException mse)
            {
                //Handling incorrect credentials
                _logger.Error(mse.Message, mse.StackTrace);
                MessageBox.Show(OSCExceptionMessages.OpportunityAuthError,
                                OSCOpportunitiesCommon.OpportunityAuthError, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (CommunicationException ce)
            {
                //Handling maximum reponse size exceeded
                _logger.Error(ce.Message, ce.StackTrace);
                MessageBox.Show(OSCExceptionMessages.MaxReceivedMessageSizeExceeded,
                                OSCOpportunitiesCommon.MaxReceivedMessageSizeExceededTitle, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex.StackTrace);
                MessageBox.Show(OSCExceptionMessages.UnexpectedError,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(null);
        }