Remove employee roles by using an workflow
# ask-stanley-ai
a
Remove employee roles by using an workflow
c
AI generated answer (using internal Slack threads):
To remove employee roles programmatically using SuiteScript, you can use the
record
module's
setValue
method to set the
role
field to an empty array. This will effectively remove all roles from the employee. Here is a sample code snippet:
Copy code
javascript
var employeeRecord = record.load({
    type: record.Type.EMPLOYEE,
    id: 'EMPLOYEE_ID',
});

employeeRecord.setValue({
    fieldId: 'role',
    value: [],
});

var recordId = employeeRecord.save({
    enableSourcing: true,
    ignoreMandatoryFields: true
});
Please replace
'EMPLOYEE_ID'
with the actual ID of the employee record you want to update. However, please note that this will only work if the roles are not being used in any dependent records. If a role has been used to log in, it cannot be deleted because the login audit trail becomes a dependent record. In such cases, you might want to consider inactivating the role instead of deleting it. Also, if you're using a workflow to trigger this script, make sure to check the 'Execute as Role' setting in the script deployment. If the workflow is running as admin, it might bypass the audience filter. You can circumvent this issue by checking the current role inside the script and do an early return if it is the excluded role. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.844370127
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.830354273
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.829626799
Please provide your feedback on this answer.