How can Okta create records on cmn_department

Chris5
Kilo Expert

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.

1 ACCEPTED SOLUTION

Chris5
Kilo Expert

After working with Okta support a confirm at this time this is not possible.

View solution in original post

16 REPLIES 16

Definitely got me on the right track here.  I ended up doing an insert / update before BR
for this that covered new company, department, cost center, and location on the user record since all 4 of those are reference fields.

 

Screen Shot 2023-03-02 at 7.39.11 PM.png

 

(function executeRule(current, previous /*null when async*/ ) {
var dept, comp, loc, getCompany, getDept, getLoc, compDisp, deptDisp, locDisp, getCost, cost, costDisp;
comp = current.company;
compDisp = current.company.getDisplayValue();
dept = current.department;
deptDisp = current.department.getDisplayValue();
loc = current.location;
locDisp = current.location.getDisplayValue();
cost = current.cost_center;
costDisp = current.cost_center.getDisplayValue();
if (current.company.changes() && !compDisp && comp) {
getCompany = new GlideRecord('core_company');
getCompany.addEncodedQuery('name=' + comp + '^ORsys_id=' + comp);
getCompany.query();
if (getCompany.next()) {
//don't do anything. Just a safety check against creating a duplicate company
} else {
getCompany.newRecord();
getCompany.name = comp;
getCompany.notes = 'DO NOT DELETE: Company';
getCompany.insert();
current.company = getCompany.sys_id;
}
}
if (current.department.changes() && !deptDisp && dept) {
getDept = new GlideRecord('cmn_department');
getDept.addEncodedQuery('name=' + dept + '^ORsys_id=' + dept);
getDept.query();
if (getDept.next()) {
//don't do anything. Just a safety check against creating a duplicate department
} else {
getDept.newRecord();
getDept.name = dept;
getDept.description = 'Department created by Okta';
getDept.insert();
current.department = getDept.sys_id;
}
}
if (current.location.changes() && !locDisp && loc) {
getLoc = new GlideRecord('cmn_location');
getLoc.addEncodedQuery('name=' + loc + '^ORsys_id=' + loc);
getLoc.query();
if (getLoc.next()) {
//don't do anything. Just a safety check against creating a duplicate location
} else {
getLoc.newRecord();
getLoc.name = loc;
getLoc.insert();
current.location = getLoc.sys_id;
}
}
if (current.cost_center.changes() && !costDisp && cost) {
getCost = new GlideRecord('cmn_cost_center');
getCost.addEncodedQuery('name=' + cost + '^ORsys_id=' + cost);
getCost.query();
if (getCost.next()) {
//don't do anything. Just a safety check against creating a duplicate cost center
} else {
getCost.newRecord();
getCost.name = cost;
getCost.insert();
current.cost_center = getCost.sys_id;
}
}
})(current, previous);

Hi @ctsmith, if you can mark my answer as Helpful i will be grateful 🙂