locked
Retrieve Active invoices from crm 2011 using asp.net RRS feed

  • Question

  • User555090508 posted

    hiiii...

    i want to retrive only active records from crm.. below is my code but  it retrieve all invoices from crm..

    public DataTable getactiveInvoiceDAL(string accountId)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID");
    
            dt.Columns.Add("Invoice ID");
            dt.Columns.Add("Invoice Name");
            dt.Columns.Add("Total Amount");
            dt.Columns.Add("Due Date");
            dt.Columns.Add("Date Delivered");
    
    
            try
            {
                credentials.UserName.UserName = ConfigurationManager.AppSettings["username"];
    
                credentials.UserName.Password = ConfigurationManager.AppSettings["userPassword"];
    
                deviceCredentials.UserName.UserName = ConfigurationManager.AppSettings["dusername"];
                deviceCredentials.UserName.Password = ConfigurationManager.AppSettings["duserid"];
    
                organizationUri = new Uri(ConfigurationManager.AppSettings["orgurl"]);
    
                homeRealmUri = null;
                using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, deviceCredentials))
                {
                    IOrganizationService service = (IOrganizationService)serviceProxy;
    
                    ConditionExpression condition1 = new ConditionExpression();
                    condition1.AttributeName = "customerid";
                    condition1.Operator = ConditionOperator.Equal;
                    condition1.Values.Add(accountId);
                   
                    ConditionExpression condition2 = new ConditionExpression();
                    condition2.AttributeName = "statecode";
                    condition2.Operator = ConditionOperator.Equal;
                    condition2.Values.Add(0);
                    
         
                    
                    
                    
                    FilterExpression filter1 = new FilterExpression();
                    filter1.Conditions.Add(condition1);
                    filter1.Conditions.Add(condition2);
                   
                    
    
                    QueryExpression query = new QueryExpression("invoice");
                    query.ColumnSet.AddColumns("name", "invoiceid", "invoicenumber", "duedate", "datedelivered", "totalamount");
                    query.Criteria.AddFilter(filter1);
    
                    EntityCollection result1 = service.RetrieveMultiple(query);
                    userDetail _userDetail = new userDetail();
    
                    if (result1.Entities.Count > 0)
                    {
                        foreach (var a in result1.Entities)
                        {
                            DataRow dr = dt.NewRow();
                            dr["ID"] = a.Attributes["invoiceid"].ToString();
                            if (a.Attributes.Contains("name"))
                            {
                                dr["Invoice Name"] = a.Attributes["name"].ToString();
                            }
    
                            if (a.Attributes.Contains("invoicenumber"))
                            {
                                dr["Invoice ID"] = a.Attributes["invoicenumber"].ToString();
                            }
                            if (a.Attributes.Contains("duedate"))
                            {
                                var d = a.Attributes["duedate"].ToString();
                                DateTime m = Convert.ToDateTime(d);
                                dr["Due Date"] = m;
                            }
                            if (a.Attributes.Contains("datedelivered"))
                            {
                                var d = a.Attributes["datedelivered"].ToString();
                                DateTime m = Convert.ToDateTime(d);
                                dr["Date Delivered"] = m;
                            }
    
                            if (a.Attributes.Contains("totalamount"))
                            {
                                Money mon = (Money)a.Attributes["totalamount"];
                                decimal amount = mon.Value;
                                dr["Total Amount"] = amount;
                            }
                            dt.Rows.Add(dr);
                        }
    
                    }
                    return dt;
                }
            }
            catch (System.Exception excep)
            {
                return null;
            }
        }



    Tuesday, January 29, 2013 3:03 AM

All replies

  • User-1662538993 posted

    What do you mean by only active invoice?

    What is the condition to find out active invoice like on the basis of any date column or any flag that will indicate in your database table?

    You can then have your query and filter on that column.

    Tuesday, January 29, 2013 8:57 AM