
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 02:55 PM
I have set up Okta on my instance and currently use it to provision users. What I would like to do next is have Okta create records on cmn_department. When a new department is created in AD I would like it to be added to ServiceNow.
I think I need to use REST API but I'm not really sure where to get started. Any help is really appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2019 12:59 PM
After working with Okta support a confirm at this time this is not possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 10:53 AM
I am facing the same issue now. Could you please help me to fix this issue. We are getting user data from Okta but Departments are not getting created in the department table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 11:20 AM
Hey Saidarao, After spending about 4 hours on zoom with Okta and ServiceNow we determined it was not possible.
I ended us scrapping Okta to provision accounts and used LDAP instead. Sorry this is not super helpful. Okta did imply if they see more appetite for the feature it would entertain adding it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2020 11:46 PM
Actually....
I'm doing a similar thing for Azure AD creating a user record and therefore potentially new departments.
If you create a field on the user record called Okta Department as a string, then it can populate that. All you now need to do is then use a before business rule (insert and update) to check if that department currently exists, if it does the assign that to the actual "department" field, if it doesn't...create it and then assign that sys_id to the current department field.
Like this...
(function executeRule(current, previous /*null when async*/ ) {
var depName = current.u_azure_department;
var gr = new GlideRecord("cmn_department");
gr.addQuery("name", depName);
gr.setLimit(1);
gr.query();
if (!gr.next()) {
gr.setValue('name', depName);
gr.setValue('id','0000');
gr.setValue ('description','New Department created by Azure integration, further information of this department is required.');
gr.update();
}
current.department = gr.sys_id;
current.update();
})(current, previous);
You can then take the u_okta_department off of all form views and it will work swimmingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 08:56 AM
This is an excellent script- thank you. I was banging my head on the wall with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2022 09:04 AM
For those who have this same issue below Business Rule should help. I spot that Okta puts value to Department field but if we don't have this value in cmn_department table value is not displayed. However if you run below background script it will display value
//Background script for check
var gr = new GlideRecord('sys_user');
gr.get('user_name','username');
gs.print(gr.department);
//onBefore Update Business Rule on sys_user table
(function executeRule(current, previous /*null when async*/ ) {
if (current.department != '') {
var d = new GlideRecord('cmn_department');
d.addQuery('name', current.department.getDisplayValue());
d.query();
if (d.next()) {
current.department = d.sys_id;
} else {
d.initialize();
d.name = current.department;
d.description = 'Department created based on value from Okta sync';
var deptSysId = d.insert();
//current.setValue('department', deptSysId);
current.department = deptSysId;
}
}
})(current, previous);