Let the platform do the work

Calculated Field - Setting Field Conditions Based on User Attributes


This article will walk through how to combine the currentUserField() function, which translates a field value on the Users module to a string value, with the equal() function in a Sugar Logic formula. The formula is evaluated based on the currently logged-in user to conditionally set a field on the leads record to "Read Only". 

For more information on Sugar Logic and Calculated Fields, please refer to the Introduction to Calculated Fields article. 

Use Case

As a sales leader, when an account rep enters a lead, I want the lead's Account Name field to be required because account reps are only creating leads from our existing accounts. When other users create leads, that field should not be required.


You will need to be familiar with the following actions that are not explained in this article:

  • Adding fields with Studio
  • Altering layouts with Studio

For additional information on adding fields and editing layouts, please refer to the Studio documentation in the Administration Guide.


This example will use the Sugar Logic function named currentUserField(), which evaluates fields in the Users module for the currently logged-in user that are marked "Make visible for calculations". This is a special field option found only on the Users module and used solely for the currentUserField() function. Combined with the equal() function to evaluate field value conditions as true or false, the formula will set the calculated field as required for users with the job title "Account Rep" but not required for anyone else.

Follow the steps below to implement this solution:

  1. Navigate to Admin > Studio > Users > Fields and click "Add Field".
  2. Fill in the fields with the following values:
    • Data Type: TextField
    • Field Name: job_title (this field cannot contain any spaces)
    • Display Label: Job Title
    • Make visible for calculations: Enabled
  3. Click "Save".
  4. Add the new field to any applicable layouts.
  5. Navigate to Admin > Studio > Leads > Fields and select "Account Name".
  6. Enable the "Required Field" checkox.
  7. Enter the following Sugar Logic formula into the "Required if" formula builder:
    equal(currentUserField("job_title_c"),"Account Rep")
  8. Save the formula.
  9. Click "Save" at the top of the field editor.
  10. Navigate to Admin > User Management.
  11. Confirm that any user who is an account rep has the exact value "Account Rep" (case sensitive) in the Job Title field for their user record.

Formula Breakdown

The currentUserField() function converts the value of a field in the Users module to a string of characters, comparable to the value of a Textfield, that can then be evaluated by other SugarLogic functions. We then use the equal() function to compare the result with our desired value, "Account Rep". The function returns "true" if the two strings match or "false" if they do not. The lead's Account Name field is then required if the function returns "true".


To test this formula, log in to Sugar as a user with the Job Title value "Account Rep". Attempt to create a new lead or edit a lead without an account name. If the formula is working correctly, then you will not be able to save the lead without providing a value for the Account Name field.