locked
CRM 4: Auto numbering field RRS feed

  • Question

  • Hi all,

    I need to create a custom field that should contain an auto incremental field, i.e when creating the first record the field value should be 1, next record 2, next record 3, and so on...

    I have found a sample in the sdk that generate a random number for the newly created record but I need it to be a serial number not a random number

     

    anyway to do it ??

     

    Thanks and best regards..


    Friday, October 14, 2011 10:55 PM

Answers

  • Hi,

    You can write a plugin that would read the max number assigned and increment one. This might not always guarantee 100% unique numbers. You can search for freely available solutions on codeplex.

    If your requirements are fancy like having prefix etc... you can also check out paid solution from CRMInnovation.

     

    HTH

    Sam

     


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Saturday, October 15, 2011 1:15 AM
  • I dont have the code handy but here are some pointers to look for in sdk

     

    In the query object you can provide order by, set this to the field that holds the autonumber field and set it to be descending order.

     

    there is also a page property that allows you to set page size and page count. set the size to 1 and page count as 1.

     

    This will return the max one record. This can also be done using FetchXML.

     

    Check out sdk for query and fetch and you should be able to find your way out.

     

    Sam

     


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Saturday, October 15, 2011 1:08 PM
  • Hi,

    The queryexpression object should have a property for orders and page. You need to set that. If you dont find it i ll tryto post code in a few hours.

     

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Wednesday, October 19, 2011 1:07 AM
  • check this http://msdn.microsoft.com/en-us/library/bb928438.aspx 

    check the orders and pageinfo example from the above link.

    set the order on the autonumber attribute in descending order.

    For pageinfo set the pagenumber as 1 and count as 1

     

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Wednesday, October 19, 2011 1:14 AM
    • Marked as answer by Mostafa Moatassem Saturday, October 22, 2011 3:09 PM
    Wednesday, October 19, 2011 1:14 AM
  • if the custom property is of the type string then just add it as string property and not crmnumber.

     

    Also after entity.properties.add... make sure you set

    context.inputproperties[target] = entity.

     

    HTH

     

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Saturday, October 22, 2011 2:46 PM
  • the line testentity = response.businessentities[0] is throwing the error. since there are no records in that entities the response does not return any entities.

     

    Add the validation to check

    if response.entities.count >0 then assign testentity = businessentities[0]

    Also the code does not require for loop to loop through properties, the contains line that you have should be enough.

    HTH

    Sam

     


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Sunday, October 23, 2011 11:34 AM

All replies

  • Hi,

    You can write a plugin that would read the max number assigned and increment one. This might not always guarantee 100% unique numbers. You can search for freely available solutions on codeplex.

    If your requirements are fancy like having prefix etc... you can also check out paid solution from CRMInnovation.

     

    HTH

    Sam

     


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Saturday, October 15, 2011 1:15 AM
  • Sam,

    Would you please help with writing the query using query by attribute ?

    thanks in advance..

    Saturday, October 15, 2011 1:33 AM
  • Hi,

    Here is the code snippet from CRM SDK. It would advisable to download the CRM SDK. It has code samples explaining most of the messages available.

    public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete)
            {
                try
                {

                    // Connect to the Organization service.
                    // The using statement assures that the service proxy will be properly disposed.
                    using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,
                                                                        serverConfig.HomeRealmUri,
                                                                        serverConfig.Credentials,
                                                                        serverConfig.DeviceCredentials))
                    {
                        // This statement is required to enable early-bound type support.
                        _serviceProxy.EnableProxyTypes();

                        _service = (IOrganizationService)_serviceProxy;

                        // *****************************************************************************************************************
                        //                                       QueryByAttribute
                        // *****************************************************************************************************************

                        //  Create query using QueryByAttribute.
                        QueryByAttribute querybyattribute = new QueryByAttribute("account");
                        querybyattribute.ColumnSet = new ColumnSet("name", "address1_city", "emailaddress1");
                        //  Attribute to query.
                        querybyattribute.Attributes.AddRange("address1_city");
                        //  Value of queried attribute to return.
                        querybyattribute.Values.AddRange("Redmond");

                        //  Query passed to service proxy.
                        EntityCollection retrieved = _service.RetrieveMultiple(querybyattribute);

                        System.Console.WriteLine("Query Using QueryByAttribute");
                        System.Console.WriteLine("===============================");

                        //  Iterate through returned collection.
                        foreach (var c in retrieved.Entities)
                        {
                            System.Console.WriteLine("Name: " + c.Attributes["name"]);
                            System.Console.WriteLine("Address: " + c.Attributes["address1_city"]);
                            System.Console.WriteLine("E-mail: " + c.Attributes["emailaddress1"]);
                        }
                        System.Console.WriteLine("===============================");
                    }
                }


                // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
                catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
                {
                    // You can handle an exception here or pass it back to the calling method.
                    throw;
                }
            }
           

    HTH

    Sam

     


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Saturday, October 15, 2011 4:36 AM
  • Actually I have developed many plugins that uses query like this, but my problem here is with a query that should retrieve the max value of a field, and Ididn't find any samples in the sdk fot this.

    Also please note that I'm using CRM 4 and not 2011

     

    If you could help me with creating a query like this it would be appreciated

     

    Thanks and best regards..

    Saturday, October 15, 2011 10:05 AM
  • Hi,

    Below URLs will be useful.

    http://weblogs.asp.net/gayanperera/archive/2008/10/23/crm-4-incremental-numbering-for-any-entity.aspx

    http://social.microsoft.com/Forums/en-IE/crmdevelopment/thread/fab8995f-2158-4199-a4b6-206adaa27406

     

     

     


    Thanks, Ankit Shah
    Inkey Solutions, India.
    Microsoft Certified Business Management Solutions Professionals
    http://www.inkeysolutions.com/MicrosoftDynamicsCRM.html
    Saturday, October 15, 2011 10:37 AM
  • I dont have the code handy but here are some pointers to look for in sdk

     

    In the query object you can provide order by, set this to the field that holds the autonumber field and set it to be descending order.

     

    there is also a page property that allows you to set page size and page count. set the size to 1 and page count as 1.

     

    This will return the max one record. This can also be done using FetchXML.

     

    Check out sdk for query and fetch and you should be able to find your way out.

     

    Sam

     


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Saturday, October 15, 2011 1:08 PM
  • Dears Sam,

    Here is the plugin full code sample:

     

    using System;
    using System . Collections . Generic;
    using System . Linq;
    using System . Text;
    
    using Microsoft . Crm . Sdk;
    using Microsoft . Crm . SdkTypeProxy;
    using Microsoft . Crm . Sdk . Query;
    using System . Web . Services . Protocols;
    
    namespace AutoNumber
    {
        public class AutoNumber:IPlugin
        {
            public void Execute(IPluginExecutionContext context)
            {
                try
                {
                    ICrmService service = context.CreateCrmService(false);
    
                    DynamicEntity CustomEntity = new DynamicEntity ( );
    
                    QueryExpression RetrieveCustomFieldQuery = new QueryExpression();
                    RetrieveCustomFieldQuery . EntityName = "new_field";
                    RetrieveCustomFieldQuery . ColumnSet = new ColumnSet ( new string [ ] { "new_field"} );
    
                    //end of the query////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
                    //start retrieve multiplerequest//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    RetrieveMultipleRequest RMRequest = new RetrieveMultipleRequest ( );
                    RMRequest . Query = RetrieveCustomFieldQuery;
                    RMRequest . ReturnDynamicEntities = true;
                    //end of retrievemultiple request//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
                    //start retrieve multipleresponse//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    RetrieveMultipleResponse RMResponse = ( RetrieveMultipleResponse ) service . Execute ( RMRequest );
                    //end of retrievemultiple response//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
                    //result length
                    int count = RMResponse . BusinessEntityCollection . BusinessEntities . Count ( );
    
                    //prepare variables to receive Quote data
                    String [ ] customFieldVal = new String [ count ];
    
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////
                    for (int i = 0; i < count; i++)
                    {
                        //receive quote data////////////////////////////////////////////////////////////////////////////////////////////////////
                        CustomEntity = (DynamicEntity)RMResponse.BusinessEntityCollection.BusinessEntities[i];
    
                        if (CustomEntity.Properties.Contains("new_field"))
                            customFieldVal[i] = CustomEntity.Properties["new_field"].ToString();
                    }
                }
                catch (Exception e)
                {
                    throw new NotImplementedException(e.Message, e);
                }
            }
        }
    }
    
    

     

    This plugin retrieves all values of a custom field, would you please help me modify the query to retrieve only the max value

     

    Thanks and best regards..


    Tuesday, October 18, 2011 8:39 PM
  • Hi,

    The queryexpression object should have a property for orders and page. You need to set that. If you dont find it i ll tryto post code in a few hours.

     

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Wednesday, October 19, 2011 1:07 AM
  • check this http://msdn.microsoft.com/en-us/library/bb928438.aspx 

    check the orders and pageinfo example from the above link.

    set the order on the autonumber attribute in descending order.

    For pageinfo set the pagenumber as 1 and count as 1

     

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Wednesday, October 19, 2011 1:14 AM
    • Marked as answer by Mostafa Moatassem Saturday, October 22, 2011 3:09 PM
    Wednesday, October 19, 2011 1:14 AM
  • Dear Sam,

    Thanks alot, I did it :)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Crm.Sdk.Query;
    using System.Web.Services.Protocols;
    
    namespace AutoNumber
    {
        public class AutoNumber : IPlugin
        {
            public void Execute(IPluginExecutionContext context)
            {
                try
                {
                    ICrmService service = context.CreateCrmService(false);
    
                    DynamicEntity NewEntity = new DynamicEntity();
    
                    QueryExpression Query = new QueryExpression();
                    Query.EntityName = "new_entity";
                    Query.ColumnSet = new ColumnSet(new string[] { "new_entitynumber" });
                    //sort retrieved values
                    Query.AddOrder("new_entitynumber", OrderType.Descending);
    
                    //limit then umber of retrieved records to 1 record
                    PagingInfo pageInfo = new PagingInfo();
                    pageInfo.Count = 1;
                    pageInfo.PageNumber = 1;
                    Query.PageInfo = pageInfo;
    
                    //end of the query////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
                    //start retrieve multiplerequest//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    RetrieveMultipleRequest ReteiveRequest = new RetrieveMultipleRequest();
                    ReteiveRequest.Query = Query;
                    ReteiveRequest.ReturnDynamicEntities = true;
                    //end of retrievemultiple request//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
                    //start retrieve multipleresponse//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    RetrieveMultipleResponse RetrieveResponse = (RetrieveMultipleResponse)service.Execute(ReteiveRequest);
                    //end of retrievemultiple response//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
                    //result length
                    int requestCount = RetrieveResponse.BusinessEntityCollection.BusinessEntities.Count();
    
                    //prepare variables to receive Quote data
                    String[] RequestNumber = new String[requestCount];
    
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////
                    for (int i = 0; i < requestCount; i++)
                    {
                        //receive quote data////////////////////////////////////////////////////////////////////////////////////////////////////
                        NewEntity = (DynamicEntity)RetrieveResponse.BusinessEntityCollection.BusinessEntities[i];
    
                        if (NewEntity.Properties.Contains("new_entitynumber"))
                            RequestNumber[i] = NewEntity.Properties["new_entitynumber"].ToString();
                    }
    
                    int maxRequestNumber = Convert.ToInt32(RequestNumber[0]);
                    //throw new InvalidPluginExecutionException("request number" + maxRequestNumber);
                }
                catch (Exception e)
                {
                    throw new NotImplementedException(e.Message, e);
                }
            }
        }
    }
    
    

    But the problem now is how to update the record while creating it ??

    I know how to update the record that is already created using its GUID, but I don't know how to do it with a newly created record as I doesn't have a GUID yet

     

    thanks and best regards..

    Friday, October 21, 2011 7:43 PM
  • You need to create a plugin for this. The plugin should trap the Create message of your entity. In the pre-event of this message, you get an object of the entity that you were trying to create from CRM form. Modify this dynamic entity to add a new property to its properties collection for the numbering attribute. Assign it the value that you get from the above code. 

    Now when CRM actually saves the record it would have stored the number field with the entity.

    The entire code above would be a part of this plugin.

    The sdk has samples for plugins. Please refer to sdk for further details and sample code.

    If this resolves your problem, please make sure to mark this response as answer to close this thread.

    Thanks!

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Saturday, October 22, 2011 1:17 AM
    Saturday, October 22, 2011 1:17 AM
  • Dear Sam,

    Below is the full plugin that I have wrote to find the max number, increment it then assign it to the newly created record:

     

    using System;
    
    using System.Collections.Generic;
    
    using System.Text;
    
    using Microsoft.Crm.Sdk;
    
    using Microsoft.Crm.SdkTypeProxy;
    
    using Microsoft.Crm.Sdk.Query;
    
    using System.Web.Services.Protocols;
    
    namespace CRM.Customization.AutoNumber
    {
    
        public class AutoNumberPlugIns : IPlugin
        {
    
            DynamicEntity entity = null;
    
            String maxNumber;
    
            int nextMaxNumber;
    
            #region IPlugin Members
    
            public void Execute(IPluginExecutionContext context)
            {
    
                if (context.InputParameters.Properties.Contains("Target") &&
    
                context.InputParameters.Properties["Target"] is DynamicEntity)
                {
    
                    entity = (DynamicEntity)context.InputParameters.Properties["target"];
    
                    ICrmService service = context.CreateCrmService(true);
    
                    if (entity.Name == "new_request")
                    {
    
                        // Find maximum number
    
                        try
                        {
                            maxNumber = FindMaxNumber(service);
    
                            //throw new InvalidPluginExecutionException(maxNumber);
                        }
                        catch (Exception e)
                        {
                            throw new NotImplementedException(e.Message, e);
                        }
    
                        nextMaxNumber =  Convert.ToInt32( maxNumber ) + 1;
    
                        //throw new InvalidPluginExecutionException(nextMaxNumber.ToString());
    
                        try
                        {
                            CrmNumber nextNumber = new CrmNumber();
    
                            nextNumber.Value = nextMaxNumber;
    
                            //throw new InvalidPluginExecutionException(nextNumber.Value.ToString());
    
                            CrmNumberProperty uniqueNo = new CrmNumberProperty();
    
                            try
                            {
                                uniqueNo = new CrmNumberProperty("new_requestnumber", nextNumber);
                            }
                            catch (Exception e)
                            {
                                throw new NotImplementedException(e.Message, e);
                            }
    
                            entity.Properties.Add(uniqueNo);
                        }
                        catch (Exception e)
                        {
                            throw new NotImplementedException(e.Message, e);
                        }
    
                    }
    
                }
    
            }
    
            private String FindMaxNumber(ICrmService service)
            {
    
                String uniqueNumber = "";
    
                QueryExpression query = new QueryExpression();
    
                query.EntityName = "new_request";
    
                ColumnSet cols = new ColumnSet();
    
                cols.AddColumn("new_requestnumber");
    
                query.ColumnSet = cols;
    
                query.AddOrder("new_requestnumber", OrderType.Descending);
    
                PagingInfo pageInfo = new PagingInfo();
    
                pageInfo.Count = 1;
    
                pageInfo.PageNumber = 1;
    
                query.PageInfo = pageInfo;
    
                RetrieveMultipleRequest request = new RetrieveMultipleRequest();
    
                request.Query = query;
    
                request.ReturnDynamicEntities = true;
    
                RetrieveMultipleResponse response = (RetrieveMultipleResponse)service.Execute(request);
    
                DynamicEntity testEntity = (DynamicEntity)response.BusinessEntityCollection.BusinessEntities[0];
    
                for (int i = 0; i < testEntity.Properties.Count; i++)
                {
    
                    if (testEntity.Properties.Contains("new_requestnumber"))
                    {
    
                        try
                        {
                            uniqueNumber = testEntity.Properties["new_requestnumber"].ToString();
                        }
                        catch (Exception e)
                        {
                            throw new NotImplementedException(e.Message, e);
                        }
                        //maxNo = uniqueNumber.ToString();
    
                    }
    
                }
    
                return uniqueNumber;
    
            }
        }
        
        #endregion
    }
    

    But for some reasons, and error occurred while saving the record:

    And error has occurred, try this action again...

     

    I have registered the plugin in the create message for the custom entity, on Pre-Stage.

    I think the whole problem lies in here:

    CrmNumber nextNumber = new CrmNumber();
    
                            nextNumber.Value = nextMaxNumber;
    
                            //throw new InvalidPluginExecutionException(nextNumber.Value.ToString());
    
                            CrmNumberProperty uniqueNo = new CrmNumberProperty();
    
                            try
                            {
                                uniqueNo = new CrmNumberProperty("new_requestnumber", nextNumber);
                            }
                            catch (Exception e)
                            {
                                throw new NotImplementedException(e.Message, e);
                            }
    
                            entity.Properties.Add(uniqueNo);
    

    as the custom field is of type nvarchar and the assigned value is of type CrmNumber.

    Please advise..

     

    Saturday, October 22, 2011 2:29 PM
  • if the custom property is of the type string then just add it as string property and not crmnumber.

     

    Also after entity.properties.add... make sure you set

    context.inputproperties[target] = entity.

     

    HTH

     

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Saturday, October 22, 2011 2:46 PM
  • You can also debug plugins. If you are developing on crm server then attach the w3p process.

    http://msdn.microsoft.com/en-us/library/cc151088.aspx

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Saturday, October 22, 2011 2:50 PM
  • Dear Sam, thanks alot for your help finally it works :)

    Here the full code for he plugin:

    using System;
    
    using System.Collections.Generic;
    
    using System.Text;
    
    using Microsoft.Crm.Sdk;
    
    using Microsoft.Crm.SdkTypeProxy;
    
    using Microsoft.Crm.Sdk.Query;
    
    using System.Web.Services.Protocols;
    
    namespace CRM.Customization.AutoNumber
    {
    
        public class AutoNumberPlugIns : IPlugin
        {
    
            DynamicEntity entity = null;
    
            String maxNumber;
    
            int nextMaxNumber;
    
            #region IPlugin Members
    
            public void Execute(IPluginExecutionContext context)
            {
    
                if (context.InputParameters.Properties.Contains("Target") &&
    
                context.InputParameters.Properties["Target"] is DynamicEntity)
                {
    
                    entity = (DynamicEntity)context.InputParameters.Properties["target"];
    
                    ICrmService service = context.CreateCrmService(true);
    
                    if (entity.Name == "new_request")
                    {
    
                        // Find maximum number
    
                        try
                        {
                            maxNumber = FindMaxNumber(service);
    
                        }
                        catch (Exception e)
                        {
                            throw new NotImplementedException(e.Message, e);
                        }
    
                        nextMaxNumber =  Convert.ToInt32( maxNumber ) + 1;
    
                        try
                        {
                            CrmNumber nextNumber = new CrmNumber();
    
                            nextNumber.Value = nextMaxNumber;
    
                            StringProperty uniqueNo = new StringProperty();
    
                            try
                            {
                                uniqueNo = new StringProperty("new_requestnumber", nextNumber.Value.ToString());
                            }
                            catch (Exception e)
                            {
                                throw new NotImplementedException(e.Message, e);
                            }
    
                            entity.Properties.Add(uniqueNo);
                        }
                        catch (Exception e)
                        {
                            throw new NotImplementedException(e.Message, e);
                        }
    
                    }
    
                }
    
            }
    
            private String FindMaxNumber(ICrmService service)
            {
    
                String uniqueNumber = "";
    
                QueryExpression query = new QueryExpression();
    
                query.EntityName = "new_request";
    
                ColumnSet cols = new ColumnSet();
    
                cols.AddColumn("new_requestnumber");
    
                query.ColumnSet = cols;
    
                query.AddOrder("new_requestnumber", OrderType.Descending);
    
                PagingInfo pageInfo = new PagingInfo();
    
                pageInfo.Count = 1;
    
                pageInfo.PageNumber = 1;
    
                query.PageInfo = pageInfo;
    
                RetrieveMultipleRequest request = new RetrieveMultipleRequest();
    
                request.Query = query;
    
                request.ReturnDynamicEntities = true;
    
                RetrieveMultipleResponse response = (RetrieveMultipleResponse)service.Execute(request);
    
                DynamicEntity testEntity = (DynamicEntity)response.BusinessEntityCollection.BusinessEntities[0];
    
                for (int i = 0; i < testEntity.Properties.Count; i++)
                {
    
                    if (testEntity.Properties.Contains("new_requestnumber"))
                    {
    
                        try
                        {
                            uniqueNumber = testEntity.Properties["new_requestnumber"].ToString();
                        }
                        catch (Exception e)
                        {
                            throw new NotImplementedException(e.Message, e);
                        }
                        //maxNo = uniqueNumber.ToString();
    
                    }
    
                }
    
                return uniqueNumber;
    
            }
        }
        
        #endregion
    }
    


    Saturday, October 22, 2011 3:18 PM
  • Dear Sam,

    I have a bug while creating the first record, it always display an "index out of range....." error, I know this occurs cause the returned value is null (as there is no max number), please advise on where on the above code to validate that the returned value from the query is not null to proceed with assigning the uniqueNumber otherwise to set it to zero

     

    thanks and best regards..

    Sunday, October 23, 2011 11:16 AM
  • the line testentity = response.businessentities[0] is throwing the error. since there are no records in that entities the response does not return any entities.

     

    Add the validation to check

    if response.entities.count >0 then assign testentity = businessentities[0]

    Also the code does not require for loop to loop through properties, the contains line that you have should be enough.

    HTH

    Sam

     


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Sunday, October 23, 2011 11:34 AM