How to create a single demand when selecting multiple idea from the list of idea using ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2024 02:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2024 04:22 AM
To create a single demand when selecting multiple ideas from a list using UI action in ServiceNow, you can follow these general steps:
- Navigate to "System UI" -> "UI Actions" in ServiceNow.
- Create a new UI Action with the desired name and settings.
- Define the form context and conditions for the UI action.
- Ensure that the UI action is available on the desired form or list.
- Write a script in the "Script" field of the UI Action.
- Use JavaScript to loop through the selected ideas and create a single demand record.
- You can use GlideRecord to interact with the ServiceNow tables.
Example script (assuming 'Idea' and 'Demand' are table names):
// Get selected ideas
var selectedIdeas = g_list.getChecked();
// Create a new Demand record
var demandGr = new GlideRecord('demand');
demandGr.initialize(); // Set default values if needed
demandGr.setValue('name', 'New Demand Name'); // Set demand fields
// Loop through selected ideas and link to the demand
for (var i = 0; i < selectedIdeas.length; i++) {
var ideaSysId = selectedIdeas[i];
// Query for the selected idea
var ideaGr = new GlideRecord('idea');
if (ideaGr.get(ideaSysId)) {
// Link the idea to the demand
demandGr.setValue('idea_link', ideaSysId); // Adjust field name as needed
}
}
// Insert the demand record
var demandSysId = demandGr.insert();
// Optionally, perform additional actions or show a confirmation message
gs.addInfoMessage('Demand created with ID: ' + demandSysId);
Please adapt the script according to your actual table and field names.
- Save the UI action and test it on the relevant form or list to ensure it works as expected.
Please mark helpful and accept as solution if this will helps you.
Thanks & Regards,
Sayali Gurav