How to make Varaible to auto populate user department in record producer

akshayp
Tera Expert

So, i have one record producer, and there is one variable on it 'Department'

  i want this variable to auto populate value of department from user table and it should be read only and hence i was thinking to use Default value to get this done.

  but, if user don't have department then this variable should be editable

 

so anyone can help me how i can do this, do i need to script include for making it editable as default value can't do that i guess

 

Thanks!!

1 ACCEPTED SOLUTION

@akshayp ,

Below is the modified code 

var deptField = 'department'; // replace with the name of the 'Department' field on your form
var userDept = g_user.department;
if (userDept) {
  // If the user has a department value, set the value and make the field read-only
  g_form.setValue(deptField, userDept);
  g_form.setReadOnly(deptField, true);
} else {
  // If the user doesn't have a department value, make the field editable
  g_form.setReadOnly(deptField, false);
}
Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

View solution in original post

5 REPLIES 5

@akshayp ,

Below is the modified code 

var deptField = 'department'; // replace with the name of the 'Department' field on your form
var userDept = g_user.department;
if (userDept) {
  // If the user has a department value, set the value and make the field read-only
  g_form.setValue(deptField, userDept);
  g_form.setReadOnly(deptField, true);
} else {
  // If the user doesn't have a department value, make the field editable
  g_form.setReadOnly(deptField, false);
}
Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you