Skip to content

Fortified IDDocs

ScriptEval Examples

This document contains a few examples of ScriptEval configurations

Increment the value of userAccountControl with +2

Section titled “Increment the value of userAccountControl with +2”

The attribute userAccountControl will control how an AD account can be used. The numeric value of an active account can always be incremented by 2 in order to disable the account.

The property item.userAccountControl is fetched in the flow by an LDAPSearch, and will therefore be stored as a string value in an array.

{
"name": "ScriptEval",
"description": "Add +2 to userAccountControl",
"config": {
"source": "items.forEach((id, item) => { const val = item.userAccountControl[0]; const increment = 2; if (val !== '' && !isNaN(val)) { item.userAccountControl[0] = String(Number(val) + increment); }});"
}
}

Some json-data is present in the state.

The item property customer is created in the flow from a previous request

{
"name": "ItemPropertyAdd",
"config": {
"values": {
"customer": "@json:${state.body.ocs.data.users.all}"
}
}
}

The script will create a new item from the content of the customer property.

{
"name": "ScriptEval",
"config": {
"source": "items.item('abc123').customer.forEach((value) => {var item= items.create(value); item.customer=value;});"
}
}

Generate sAMAccountName by substring of givenName and sn

Section titled “Generate sAMAccountName by substring of givenName and sn”

The item property sAMAccountName will be added to all items. The property will be created by the first 3 characters from givenName and the first 3 characters from sn.

{
"name": "ScriptEval",
"config": {
"source": "items.forEach((id, item) => {const givenName = item.givenName[0];const sn = item.sn[0];var sAMAccountName = givenName.substring(0,3) + sn.substring(0,3) ;item.sAMAccountName = sAMAccountName;});"
}
}

Count number of days since lastLogonTimeStamp

Section titled “Count number of days since lastLogonTimeStamp”

The item property days will be added to all items. The property will contain the date diff between L (containing the value of lastLogonTimeStamp) and current time.

{
"name": "ScriptEval",
"config": {
"source": "items.forEach((id, item) => { const ms_date = BigInt(item.ms_date.toString()); const lastLogonTimeStamp = BigInt(item.L.toString()); const d1 = (ms_date / 10000n) - 11644473600000n; const d2 = (lastLogonTimeStamp / 10000n) - 11644473600000n; const diffMs = Number(d1 - d2); const dagar = diffMs / (1000 * 60 * 60 * 24); item.days = String(Math.round(dagar)); });"
}
}

Merge the content from item.secretary with each value from request.adExtraGroupManagers.pending_add.id and remove each value from request.adExtraGroupManagers.pending_remove.id. The result is stored as item.secretary.

{
"name": "ScriptEval",
"config": {
"source": "items.forEach((id, item) => { const current = Array.isArray(item.secretary) ? item.secretary : (item.secretary ? [item.secretary] : []); const pendingAdd = request.adExtraGroupManagers && request.adExtraGroupManagers.pending_add ? request.adExtraGroupManagers.pending_add : []; const pendingRemove = request.adExtraGroupManagers && request.adExtraGroupManagers.pending_remove ? request.adExtraGroupManagers.pending_remove : []; const addIds = pendingAdd.map(u => u.id).filter(Boolean); const removeIds = new Set(pendingRemove.map(u => u.id).filter(Boolean)); item.secretary = [...new Set(current.concat(addIds).filter(dn => !removeIds.has(dn)))]; });"
}
}