- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 08:21 PM
HI All,
Can anyone please help us on the below requirement.
We have one field called "Count" and it's string type.
And when an end user enter any numbers in the field we need to automatically add the " - " symbol after every two numbers.
Examples:
--> 12-34-56
--> 32-3
--> 45
Advance thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 03:44 AM
Hi All,
Many thanks for your response.
Below code working fine for us:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// //Type appropriate comment here, and begin script below
var str = newValue.toString();
var tempdata='';
for (var i=0; i<str.length; i++){
if(str[i]!='-')
{
tempdata=tempdata+str[i];
//alert(tempdata);
}
}
//alert(tempdata);
var result='';
for (var j=0; j<tempdata.length; j++){
if(j%2!=0 && j!=tempdata.length-1)
{
result=result+tempdata[j]+'-';
}else{
result=result+tempdata[j];
}
}
//alert(result);
g_form.setValue('u_count', result);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 08:31 PM
what's your exact business requirement?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 09:19 PM
Hi Ankur,
Thanks for the reply..
We have variable called "Count" (Single line text - Type), so when end user enter the numbers in "Count" field
then after every two numbers "- " ( Hyphen )symbol needs to be added automatically.
Advance thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 10:17 PM
But what's the use of that field?
May I know why to include hyphen?
You can achieve this by string manipulation but would like to understand the business use case
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 01:04 AM - edited 11-17-2022 01:06 AM
Hi Ankur,
In our organization every contract employee have some unique employee numbers, like for every two numbers one hypen is be there.
so in the count field level some users not giving hypen, so that's the reason business came up with this approach.
Thanks.