How to set a phone number on record producer?

s_s
Giga Contributor

Hello.

I created a variable to get the user to enter a phone number.

I would like to limit this variable as below.

・Only half-width numbers numbers can be entered.

・Set the maximum number of characters

Now, i set 'type' to 'Single Line Text' so should I change type too?

I appreciate it if you could answer.

1 ACCEPTED SOLUTION

Sanket Khabiya
Kilo Sage

Hi,

Please try with below solution:

Please write this code to you catalog Client Script



function onChange(control, oldValue, newValue, isLoading, isTemplate)
{
 if(isLoading || newValue==='')
 {
  g_form.showFieldMsg('mobile_no','number starting from 9/8/7 are valid','info');  //here mobile_no is your variable name
  return;
 }
 var phone = /^[789][0-9]{9}/;

 if(!phone.test(newValue)&& newValue!='')
 {
  g_form.setValue('mobile_no','');
  g_form.showFieldMsg('mobile_no','Please enter 10 digitvalid mobile number','error');
 }
}

Regards,

Sanket

View solution in original post

7 REPLIES 7

Omkar Joshi
Giga Guru

Hi,

 

Use the below code in your client script:

 Use Single Line Text.

//this script for accept only numbers.

 

var phone=g_form.getValue('number');//check your variable name
var numbers = /^[0-9]+$/;

//Accept only 10 number if you want to change change that number
if(phone.match(numbers)||phone.length!=10)
{
    //if numbers
}
else
{
      alert('Allow only digits');
      g_form.clearValue('number');//check your variable name
}

 

s_s
Giga Contributor

Sorry for lack of explanation.

The variable must be displayed on the portal.

 Is Client Script 'System Definition > Client Scripts'?

I created code as you write in 'Client Scripts', but it doesn't work.

Is the 'Catalog Client Scripts' different?

Hi,

The Catalog Client script are almost similar to Client Script with few differences.

Instead of selecting a table such as Incident for the script, select a catalog item or variable set. As your system may have a large number of catalog items, you should select a catalog item or variable set using a reference field instead of the choice list that the standard Client Script form uses.

When using an onChange() catalog client script, it is linked to a particular variable instead of a field. The system automatically populates the variable name selection list with any named variables from the catalog item or variable set selected.

Yes you need to create a Catalog Client Script with the code which Omkar provided, for the Record Producer.

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Chaitanya

Harsh Vardhan
Giga Patron

create onchange catalog client script on your variable which has been created on your form to store the number value , and make sure UI Type set as ALL in your client script  . 

 

var phone=g_form.getValue('your Varible NAme');
var numbers = /^[0-9]+$/;

//Accept only 10 number if you want to change change that number
if(phone.match(numbers)||phone.length!=10)
{
    //if numbers
}
else
{
      alert('Allow only digits');
      g_form.clearValue('your Varible NAme');
}