locked
CRM 2013 On-Premise > How to implement sequential numbering for records? RRS feed

  • Question

  • Hi All,

    I don't know if someone could advise me on the following.

    I have two entities, Transport Routes and Stops with a 1:N relationship. I want to auto-number the Stops records sequentially (1, 2, 3, 4, etc.)  but want to start at 1 within each Transport Route. How should go about it? Is it possible to achieve this with JS, or would that be a bit clumsy and would you recommend a plugin instead?

    I have an auto-numbering solution (AdvancedCRMAutoNumber from Xbitz) but that will not restart the counter position to 1 for each Transport Route - at least to me knowledge it cannot.

    Would appreciate any help!

    Thanks, Viktor

    Wednesday, March 25, 2015 10:16 AM

Answers

  • Viktor,

    I think this scenario is easier to achieve with a plugin that fires on the create (Pre-event and modify the target) of your 'Route Waypoint' entity. In the plugin:

    • Retrieve your transport route
    • Retrieve all route waypoints from the transport route descending by the autonumbering field
    • If no route waypoints on the transport route, autonumber = 1
    • If route waypoints: get the first (list is descending on auto numbering) element and increment that number by 1
    • Fill in the autonumber on your newly created waypoint

    Hope it helps, 

    Kind regards

    • Marked as answer by viktor.j Thursday, March 26, 2015 2:28 PM
    Thursday, March 26, 2015 8:32 AM

All replies

  • Hi Viktor,

    I think it depends on the business scenario. If one route is administered by one person, then I think you are fine with JS. If more than one person can edit a route simultaneously than you have to deal with concurrency, and I would strongly recommend a plugin there.

    Regards,

    Adam

    Wednesday, March 25, 2015 2:11 PM
  • Hi Adam,

    Thanks for your reply! Suppose it's administered by one person, what logic should I use then to keep track of the number of child records (Stops) associated with the various Routes?

    I may be overcomplicating it, but my initial thought was that this auto-numbering mechanism would do the following:
       - retrieve the GUID of the parent Transport Route record
       - retrieve and count all associated Route Waypoint records to determine the counter position for the given Transport Route
       - increment that by 1
       - write it back to the new Route Waypoint record
    ... but to me that sounds way too complicated with JS and I doubt I could that.

    Would appreciate any thoughts or suggestions!

    Wednesday, March 25, 2015 3:35 PM
  • Viktor,

    I think this scenario is easier to achieve with a plugin that fires on the create (Pre-event and modify the target) of your 'Route Waypoint' entity. In the plugin:

    • Retrieve your transport route
    • Retrieve all route waypoints from the transport route descending by the autonumbering field
    • If no route waypoints on the transport route, autonumber = 1
    • If route waypoints: get the first (list is descending on auto numbering) element and increment that number by 1
    • Fill in the autonumber on your newly created waypoint

    Hope it helps, 

    Kind regards

    • Marked as answer by viktor.j Thursday, March 26, 2015 2:28 PM
    Thursday, March 26, 2015 8:32 AM
  • hi Victor,

    I think you can write plugin by following below steps.

    -->Create one field in the Transport route entity to store the sequential number.

    -->As soon creating the Transport stop record get the sequential from the Transport route and create the sequential number for the transport stop.

    -->Update the Transport route record by incriminating the sequential number field.

    So every Transport route record will have sequential number which we can start with 1 as based on the stops we can increment the number.

     

    Thursday, March 26, 2015 1:55 PM
  • Hi J_H_L,

    It may not have been clear from my posts that I was asking two different questions (1. JS or Plugin is the way to go? 2. What logic shall I use?) but you read my mind and answered both!:)

    Thanks a million!

    Thursday, March 26, 2015 2:28 PM
  • Shiva,

    I really like your suggestion too, simple and elegant.

    Thanks a lot!

    Viktor

    Thursday, March 26, 2015 2:30 PM