are workspace compatabile with multi variable set?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 09:12 AM
I was ask to link a multiple variable set into a workspace but i dont found how to make these
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 02:36 AM
Hello @Edward Novella ,
In ServiceNow, you can use the GlideScript scripting language to manage and manipulate variables and data. To link multiple variable sets into a workspace in ServiceNow, you can create a new GlideRecord object and use it to interact with the Variable Sets and Variables tables. Here's a general outline of the steps:
1. Create a Script Include (Optional):
You can create a Script Include if you want to encapsulate this functionality for reuse. To do this, navigate to "System Definition" > "Script Includes" and create a new one.
2. Write the Script to Link Variable Sets into a Workspace:
Here's an example script to link multiple variable sets into a workspace in ServiceNow:
javascript
// Instantiate a new GlideRecord object for 'workspace' (replace 'workspace' with your target table name).
var workspaceGR = new GlideRecord('workspace');
// Start a transaction to group your operations.
GlideTransaction.get().begin();
try {
// Query for the workspace you want to update (replace with your condition).
workspaceGR.addQuery('name', 'YourWorkspaceName');
workspaceGR.query();
// Check if a workspace record was found.
if (workspaceGR.next()) {
// Link Variable Set 1 to the workspace (replace 'variable_set_1' with your variable set name).
workspaceGR.variables_set_1 = 'variable_set_1_sys_id'; // You need to provide the sys_id of the variable set.
// Link Variable Set 2 to the workspace (replace 'variable_set_2' with your variable set name).
workspaceGR.variables_set_2 = 'variable_set_2_sys_id'; // You need to provide the sys_id of the variable set.
// Add more links for additional variable sets if needed.
// Update the workspace record.
workspaceGR.update();
// Commit the transaction.
GlideTransaction.get().commit();
} else {
// Workspace not found, handle the error or create a new workspace.
}
} catch (ex) {
// Handle any exceptions that may occur.
GlideTransaction.get().rollback();
gs.error('Error linking variable sets to workspace: ' + ex.getMessage());
}
This script assumes you have the sys_id of the variable sets you want to link and the name of the workspace you want to update. Make sure to replace 'YourWorkspaceName', 'variable_set_1', 'variable_set_2', and their respective sys_ids with your actual values.
3. Execute the Script:
You can execute this script in a variety of ways, such as Business Rules, Script Actions, or Scheduled Jobs, depending on your use case.
Please mark my solution correct or helpful, if applicable.
Thanks & Regards,
Chaitali Vale