Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Auto assign user based on employment type

sreeha
Tera Contributor

Hi,

 

user whose hr profile meet these conditions like employement type is contractors they should be auto assigned to contractor external role( global scope) 

4 REPLIES 4

Tanushree Maiti
Giga Sage

To automatically assign a user to a "Contractor" role (Global Scope) based on their employment type in the HR Profile, the recommended ServiceNow approach is to use a Business Rule on the sn_hr_core_profile table

 

  1. Identify the Role: Ensure the "Contractor" role exists in the global scope (e.g., contractor_external).
  2. Create a Business Rule:
    • Table: HR Profile [sn_hr_core_profile]
    • When: after (insert or update)
    • Order: 100
    • Conditions: Employment type changes to Contractor
  3. Script:  (update script as per your requirement)

Submit.

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Ankur Bawiskar
Tera Patron

@sreeha 

what's your actual business requirement?

question is not clear.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

sreeha
Tera Contributor

Hi @Ankur Bawiskar ,

 

  • Auto Assign a role to user whose Hr Profile meets the below condition like employment type is Contractor using client role assignment rule 

its_SumitNow
Mega Sage

Hi @sreeha 

To automatically assign a user to the Contractor External role (Global Scope) based on their HR Profile employment type, the recommended approach in ServiceNow is to use a Business Rule on the HR Profile table.

Step 1 — Verify the Role exists: Make sure the contractor_external role exists in the Global scope before proceeding.

Step 2 — Create a Business Rule:

Field Value

TableHR Profile [sn_hr_core_profile]
WhenAfter (Insert or Update)
Order100
ConditionEmployment Type changes to Contractor

Step 3 — Add the Script:

(function executeRule(current, previous) {
    var userId = current.user.toString();
    if (!gs.isEmpty(userId)) {
        var roleAssign = new GlideRecord('sys_user_has_role');
        roleAssign.initialize();
        roleAssign.user = userId;
        roleAssign.role = gs.getRoleID('contractor_external');
        roleAssign.insert();
    }
})(current, previous);

⚠️ Note: Update the script as per your specific business requirements and always test in a sub-production instance before deploying to production.

Hope this helps! ,if yes kindly mark helpful & Accept as Solution😊

 

Regards 

Sumit