- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2021 09:28 AM
Hello Experts,
I need to know how to select Multiple Values in a Select Box Variable without updating ACL or in a List Collector Variable without creating a custom Table for options.
I saw multiple articles which mentioned either updating an ACL or creating a custom table both are not suitable in my case. If there's any other way to achieve the same please comment you response.
Thank you.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2021 09:57 AM
To prevent duplicates from being entered, you basically have to read the current value of the MRVS and loop through the rows to see if the new value has already been used. Getting the current value of the MRVS works differently in the Service Portal, so first we need an onLoad Catalog Client Script running on the Catalog Item, not within the MRVS.
function onLoad() {
if (this) {//we only need to do this for Service Portal
//We need to make the g_form object for the parent item available from the MRVS window
this.cat_g_form = g_form;
}
}
Now when you create an onChange Catalog Client Script within the MRVS when Vulnerability Type changes, it will be able to get the value of the already-submitted rows in both Service Portal and the native UI.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var mrvs = '';
if (this) { //Service Portal method
mrvs = this.cat_g_form.getValue('mrvs_internal_name'); //internal name of your MRVS
} else { //native UI method
mrvs = parent.g_form.getValue('mrvs_internal_name');
}
if(mrvs.length>2){//native UI empty MRVS = '[]'
var obj = JSON.parse(mrvs);
for (var i = 0; i < obj.length; i++) {
if(obj[i].vulnerability_type == newValue){//replace with your variable name
g_form.clearValue('vulnerability_type');
alert('Vulnerability Type already exists in this table.');
}
}
}
}
You can add an alert on mrvs to show the JSON formatting of the MRVS value. It's a little easier to work with MRVS values in server script, so if you have later requirements needing to do something with the contents of the MRVS, try to do it in a workflow Run Script or Business Rule. The idea is similar to what's shown in the onChange script, but you don't need to parse it. So to get the value and loop through the elements would be something like this.
var mrvs = current.variables.mrvs_internal_name;
var rowCount = mrvs.getRowCount();
for(var i=0; i<rowCount; i++){
var row = mrvs.getRow(i);
gs.info('This is the value of the variable in row ' + i + ': ' + row.vulnerability_type);
}
You can also add rows or update values with this same approach. More than you need to do on this project, but good to keep in mind for future use.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2021 09:35 AM
Hi Laukik,
Here's a link to an article that I have used to create a List Collector variable without the choices being on a table or needing to create a custom table.
https://www.covestic.com/servicenow-tips-making-list-collectors-useful/
There is a step that may require you to update a read ACL on the question_choice table, but that is a very low impact change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2021 10:10 AM
Hello Brad,
Thank you for your response. As I mentioned I do not wish to make these other changes to ACLs or the baseline Client Script as mentioned in the article. Hope it does help someone with similar requirements.
As I posted this question, I'm trying to find workarounds for the same issue; while doing so the idea of using multi-row variable set popped up in my mind. I do not have enough hands on with multi-row variable set to know its limitations so posting it to get your ideas on it.
I've created a multi-row variable set with single variable of select-box, having 21 choice values. Whenever I click add and select a type from select-box it gets added to the list, which in some way does help me. I'll add the ss below.
but as you can see I can select same option more than once, which is not necessary. Please share your views on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2021 02:15 PM
If this is the approach you want to take, I can help you make it do what you want it to. We can write a script to ensure that duplicate Vulnerability Types/rows are not added to the MRVS. Do you have any other restrictions - there must be at least one value/row added? There cannot be more than x # of rows added? Are you using the native UI/Service Catalog, or Service Portal, or both? The value of the MRVS is stored as a JSON, so it can't be added to reports. That's about the only limitation if you know how to work with the JSON value wherever you might need to use this downstream - like creating a Catalog Task for each Vulnerability Type, or certain other activities if a Vulnerability Type is included in the MRVS...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2021 08:06 AM
Wow, there are multiple limitations which might affect in future. Thank you for you response. Please help me with the script to avoid duplicate. As long as I do not touch OOB functionality I'm happy. If these selection needs separate catalog tasks, then I think checkboxes will be better(easier) option. If you know how the JSON will work in this case please share that as well. And yes I'm trying to see it on both Native UI/Service Portal.
Again thank you so much for sharing this knowledge. I'm already excited to achieve this solution.