How can add suggestions on the variables field on catalog form

kpanchal
Tera Contributor

Hello All,

I need to add the suggestions on the Emp Code fields based on the combination of First Name and Last Name initials along with 3 digits to select for the new user.

 

How can I achieve the suggestions underneath the Variable field?

kpanchal_0-1703714253885.png

 

1 ACCEPTED SOLUTION

SunilKumar_P
Giga Sage

Hi @kpanchal, You can try with the onChange client script on variable name 'lastName' to get the dynamic suggestions and you need to make sure the value in lastName is entered. You can probably make the Id field readOnly untill the last is populated.

 

Dynamic Option:

onChange Client Script:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var firstLetter = g_form.getValue('first_name').split('')[0];
    var lastLetter = g_form.getValue('last_name').split('')[0];
    var randomNumber = Math.floor(Math.random() * (999 - 100 + 1) + 100);
    var finalId = firstLetter + lastLetter + randomNumber;
    g_form.showFieldMsg('unique_id', 'Suggested Id is - ' + finalId, 'info');
}

 

SunilKumar_P_4-1703729935423.png

 

Static Options:

 

You can try with example text on the variable form or show the field message using the catalog client script.

 

Client Script:

function onLoad() {
   g_form.showFieldMsg('unique_id', 'Please Enter Uique Id', 'info');
}

 

SunilKumar_P_0-1703728211549.pngSunilKumar_P_1-1703728256023.pngSunilKumar_P_2-1703728282811.png

 

Regards,

Sunil

 

 

View solution in original post

10 REPLIES 10

Siddhesh Gawade
Mega Sage
Mega Sage

Hello @kpanchal ,

 

You can user below catalog client script to generate dynamic Employee Code. As a result it will give you Combination of the initials of the First Name and Last Name fields with the random 3-digit number to form the Emp Code.

 

*** this script running on Onchange for last Name variable.

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

var firstName = g_form.getValue('first_name');
var lastName = g_form.getValue('last_name');
var empCode = firstName.charAt(0) + lastName.charAt(0) + generateRandomNumber();
g_form.showFieldMsg('employee_code', 'Suggested Emp Code: ' + empCode, 'info',true);

}

function generateRandomNumber() {
return Math.floor(100 + Math.random() * 900);
}

 

 

 After generating the code you can add more checks and conditons based on your business requirement. 

 

 

Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.


Regards,

Siddhesh