- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2025 06:34 AM
Hello everyone,
I have a catalog item that includes a Multi-Row Variable Set (MRVS) named "new_tables", which contains a variable called "table". This variable is a reference to the sys_db_object table.
I want to ensure that users cannot select the same table more than once.
For example, if a user selects ".NET Application" in the first row, it should no longer be available for selection when adding a new row.
Any thoughts?
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2025 09:06 AM
Hi @Amina El hadad ,
try this
try to alert newTables and see what you are getting
function onSubmit() {
var newTables = g_service_catalog.parent.getValue('new_tables');
newTables = newTables ? newTables : '[]';
var systemTabs = JSON.parse(newTables);
for (var i = 0; i < systemTabs.length; i++) {
if (systemTabs[i]['table'] == g_form.getValue('table')) {
g_form.addErrorMessage('table is already added');
return false;
}
}
}
if you still getting the error
Could you please share the screenshots of the error and the configuration that you have done and the MVRS and it's scripts?
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2025 10:18 AM
Hi @Amina El hadad,
I hope you are doing well! I was able to solve your issue on my PDI. Please follow below instructions to get a working solution:
- Go to your Multi-Row Variable Set "new_tables"
- Create OnSubmit Catalog Client Script with the following script: (Please ensure variable names are correct)
function onSubmit() {
var multiRow = JSON.parse(parent.g_form.getValue("new_tables"));
var obj = {
'table': g_form.getValue('table')
};
if (multiRow) {
var result = multiRow.filter(function(item) {
return (item.table == obj.table);
});
if (result.length > 0) {
g_form.addErrorMessage('You have entered the same twice');
return false;
}
}
}
Results:
As you can see below screenshot, I was unable to add ".NET Application" twice. the Error message would be displayed when you click on Add.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2025 07:15 PM
Hi @Amina El hadad,
Yes! that is definitely possible. Please follow below instructions to achieve your requirements:
1- Disable/Deactivate Existing Catalog Client Script(s) you created earlier in the previous solution(s)
2- Create OnLoad Catalog Client Script on your Variable Set
function onLoad() {
var catItemVarName = 'community_test'; //PLEASE REPLACE THIS WITH YOUR VARIABLE SET TECHNICAL NAME
var catItemVarValue = g_service_catalog.parent.getValue(catItemVarName);
var ga = new GlideAjax('RefQualifierClient'); // PLEASE USE THE SCRIPT INCLUDE WHICH IS CREATED IN NEXT STEP
ga.addParam('sysparm_name', 'setSessionData'); //function in script include
ga.addParam('sysparm_cat_item_var_name', catItemVarName);
ga.addParam('sysparm_cat_item_var_value', catItemVarValue);
ga.getXMLAnswer(getResponse);
}
function getResponse(response) {
//do nothing
}
3- Create a Script Include (Client Callable / Glide AJAX enabled) - In my example, I named it "RefQualifierClient"
4- Add the following function to your script include:
setSessionData: function() {
var sysId = [];
var catItemVarName = this.getParameter('sysparm_cat_item_var_name');
var catItemVarValue = this.getParameter('sysparm_cat_item_var_value');
var variableSetData = JSON.parse(catItemVarValue);
for (var i = 0; i < variableSetData.length; i++) {
sysId.push(variableSetData[i].table); //REPLACE "table" WITH TECHNICAL NAME OF THE REFERENCE FIELD TO sys_db_object ON YOUR VARIABLE SET
}
var session = gs.getSession().putClientData(catItemVarName, sysId);
return;
}
5 - Go to your reference variable to sys_db_object on your Variable Set. And set an advanced Reference qualifier as follow:
javascript: "sys_idNOT IN" + session.getClientData("community_test"); // REPLACE community_test WITH YOUR VARIABLE SET TECHNICAL NAME
(Please follow the comments on the give script where you need to update some input with your variable / script include names)
I tested it on my PDI and it is working as expected. Selected tables are no longer displayed when adding a new row.
I hope it helps!
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2025 08:47 AM
Hi @Chaitanya ILCR,
Yes I added the script to the MRVS, and "new_tables" is the internal name of the MRVS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2025 09:06 AM
Hi @Amina El hadad ,
try this
try to alert newTables and see what you are getting
function onSubmit() {
var newTables = g_service_catalog.parent.getValue('new_tables');
newTables = newTables ? newTables : '[]';
var systemTabs = JSON.parse(newTables);
for (var i = 0; i < systemTabs.length; i++) {
if (systemTabs[i]['table'] == g_form.getValue('table')) {
g_form.addErrorMessage('table is already added');
return false;
}
}
}
if you still getting the error
Could you please share the screenshots of the error and the configuration that you have done and the MVRS and it's scripts?
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2025 06:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2025 10:18 AM
Hi @Amina El hadad,
I hope you are doing well! I was able to solve your issue on my PDI. Please follow below instructions to get a working solution:
- Go to your Multi-Row Variable Set "new_tables"
- Create OnSubmit Catalog Client Script with the following script: (Please ensure variable names are correct)
function onSubmit() {
var multiRow = JSON.parse(parent.g_form.getValue("new_tables"));
var obj = {
'table': g_form.getValue('table')
};
if (multiRow) {
var result = multiRow.filter(function(item) {
return (item.table == obj.table);
});
if (result.length > 0) {
g_form.addErrorMessage('You have entered the same twice');
return false;
}
}
}
Results:
As you can see below screenshot, I was unable to add ".NET Application" twice. the Error message would be displayed when you click on Add.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2025 06:16 PM
Hi @Medi C,
Thank you a lot, I appreciate really your support!
Would you be able to help with hiding the table option once it has been selected, so it is no longer available for selection again instead of showing the error message?