You are viewing limited content. For full access, please sign in.

Question

Question

Is there a way to format the instance ID

asked on June 10, 2014

We are using the instance ID to populate a tracking number in Laserfiche.  The instance ID will be used to name the file and placed in a token.  Is there a way to format the number of digits the instance ID uses?  For example, we'd like it to be 5 digits with leading zeros if necessary:  00067.  How would I accomplish this?

 

Thanks,
Jen

 

0 0

Answer

APPROVED ANSWER SELECTED ANSWER
replied on June 13, 2014 Show version history

Try this:

 

$(document).ready(function () {
    var currentVal = $('.instanceId input').val();
    if (currentVal.length < 5) {
        currentVal = 10000 + Number(currentVal);
    }
    $('.instanceId input').val(currentVal);
});

Update: Better code to handle the case where the instance ID is 5 digits.

0 0

Replies

replied on June 10, 2014

You can do this with Token Formatting in Workflow. Just right click on the token, select Token Editor, and apply the formatting you'd like (in this case "D5" to make the token always fill 5 digits).

 

0 0
replied on June 10, 2014

Hi Aaron,

Thanks for the response.  I left a step out in my process.  This number needs to be displayed on the Form itself prior to being sent into Laserfiche.  So, I really need to be able to format the instance ID while in Forms. Is there a way to do that?

 

Thanks,
Jen

0 0
replied on June 11, 2014

Probably the best way to do this is to set the instance ID as the default value for a field, and then use JavaScript to format the instance ID the way you want it. Of course, this value will not be displayed for the user submitting the form (since the ID hasn't been established yet), so ideally you'll add this field to a form used after the initial submission.

 

Give the field the instanceId CSS class, and then use the following JavaScript.

 

function padDigits(number, digits) {
    return Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number;
}

$(document).ready(function() {
  $('.instanceId input').val(padDigits($('.instanceId input').val(), 5));
});

 

 


 

0 0
replied on June 12, 2014

Thanks.  That works great.  The customer had one more request.  Is there a way to change the code to have the numbers start with 1.  For example, 10000.

 

Thanks for your help.

0 0
APPROVED ANSWER SELECTED ANSWER
replied on June 13, 2014 Show version history

Try this:

 

$(document).ready(function () {
    var currentVal = $('.instanceId input').val();
    if (currentVal.length < 5) {
        currentVal = 10000 + Number(currentVal);
    }
    $('.instanceId input').val(currentVal);
});

Update: Better code to handle the case where the instance ID is 5 digits.

0 0
replied on June 13, 2014

That works great!  Thanks for your help, Eric.

0 0
replied on June 13, 2014

You're welcome!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.