4 Replies Latest reply on Dec 31, 2018 1:22 PM by wynnb

    Remove leading zeros in barcode field

    wynnb Specialist

      I'm trying to configure a barcode form to add devices to Asset Control (in EPM 2017.3.3). My question is about how to strip leading zeros from a barcode. For example, our asset tags have 8 digits, and start with zeros. So, when I scan that barcode, I want to change it from '00012345' to '12345'.


      Do I have to build a rule, and run that against the device after it is added to inventory, or can it be done on the fly in the barcode form field properties?


      Also, can I take the value from one field, and use that in another attribute? For example, if I'm entering a new monitor and the asset tag is '12345', how can I auto-populate the Device Name as 'Mon-12345'?

        • 1. Re: Remove leading zeros in barcode field
          phoffmann SupportEmployee

          Yeah - building a real-time active and/or post-processing rule is probably the easiest.


          Should only be 1-2 lines in VB  (I hope, VB still surprises me on how daft it can be) to remove leading 0's... .


          We just take the "value" given to us by the barcode. I'd kind of expect the barcode to give you "the right value" off the get-go (which the manufacturer were going to use on their own www-site)...?

          • 2. Re: Remove leading zeros in barcode field
            wynnb Specialist

            Thanks, maybe I just don't understand how to configure the rules...


            I may have got it right with a calculate data rule, using "RetValue = Abs(!Device.Asset Info.Asset Tag!)".


            Previously, I was trying a Map Data rule, but maybe those are only for copying from one attribute to another?

            • 3. Re: Remove leading zeros in barcode field
              phoffmann SupportEmployee

              I'd personally use a "Calculate" rule -- and dump the (modified) string into a NEW place / value in inventory. This gives you the option of having both values (I prefer to keep both on a rule, because there's always "some daft" situation where you'll find that you'll need the unmodified value).


              In terms of getting your thing (logic) right - that's by and large going to be a RegEx exerise (based on how your names go).


              Let's assume it's always "DEV-000001234567" ... you could start with a simple "string split" & remove the "DEV-" and then "just" remove the leading 0's ... and then re-attaching the DEV to the left-over string ... and then bringing that back as your return value.


              Hint - it always helps testing the rule in the form of a simple VB-script with input you can control (either via cmd-line or as part of the script itself) which'll allow you much easier opportunity to test things.


              Also - this may help you with "removing leading 0's" -- vbscript - how to remove leading zeroes from a string - Stack Overflow -- for instance.


              ... there you go - that should sort you out?

              1 of 1 people found this helpful
              • 4. Re: Remove leading zeros in barcode field
                wynnb Specialist

                Thanks. Yes, that's one of the sites I looked at to figure out the vbscript option. You're probablly correct about saving both versions of the value; there are a few different attributes named 'asset tag', so I could use one of the others for the original value.


                In most cases, we name our workstations with a scheme that includes the digits of the asset tag, so I also created a rule using regex that would pull those digits and write them to the system.asset tag attribute. The goal is to be able to identify those devices via the asset tag for things like doing physical inventory with a barcode scanner.