- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 11:03 AM
Hello,
I have received a requirement to receive information from OKTA that is stored as an Array into ServiceNow in the User form.
We are trying to avoid making a custom table for the data to flow into but I know ServiceNow does not have an Array field type.
Any help is appreciated, thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 12:26 PM
We solved this internally, posting solution for others.
In OKTA we put Arrays.toCsvString(user.{field}) and mapped that to our ServiceNow field, OKTA sent the array as a comma separated value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 06:00 PM
Hi @Robert_Anderson ,
You can create a list type field on user table and convert the incoming array into comma seperated value.
For example, you can check the Type field on Group [sys_user_group] table.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 08:04 PM
I think you can try something like below:
You can store JSON data in a text field. This allows you to represent arrays as strings and parse them when needed. For example, if your array data from OKTA looks like ["value1", "value2", "value3"], you can store it as a JSON string in a text field.
Let's say you have array-like data coming from OKTA, which includes a list of roles assigned to a user. This data is represented as follows: ["Role1", "Role2", "Role3"]
To store this data in a ServiceNow User form using a JSON field, follow these steps:
Create a Text Field: First, create a text field on the User form in ServiceNow where you want to store the roles. Let's call this field okta_roles.
Convert Array to JSON String: Before storing the array data, you need to convert it into a JSON string. You can use the JSON.stringify() method to convert an array to a JSON string. For example:
var rolesArray = ["Role1", "Role2", "Role3"];
var rolesJSONString = JSON.stringify(rolesArray);
This will give you a JSON string representation of the array:
["Role1", "Role2", "Role3"]
Store JSON String in Text Field: Now, you can store this JSON string in the okta_roles field on the User form in ServiceNow.
Parse JSON String When Needed: When you need to access the roles data, you can retrieve the JSON string from the okta_roles field and parse it back into an array using the JSON.parse() method. For example:
var rolesJSONString = userRecord.getValue('okta_roles'); // Assuming userRecord is the GlideRecord for the User
var rolesArray = JSON.parse(rolesJSONString);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 02:09 PM
Hello,
For 2. Convert Array to JSON String: Before storing the array data, you need to convert it into a JSON string. You can use the JSON.stringify() method to convert an array to a JSON string.
Where do I do that, would that be in OKTA or in the field settings in ServiceNow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 12:26 PM
We solved this internally, posting solution for others.
In OKTA we put Arrays.toCsvString(user.{field}) and mapped that to our ServiceNow field, OKTA sent the array as a comma separated value.