- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have req to stop the duplicates entering in MRVS.
MRVS Internal name is temp_workers_for_create_accounts
I write onsubmit client script under the variable set. but not working and g_form.getValue('temp_workers_for_create_accounts') is always empty.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Since this Catalog Client Script applies to the variable set, not the Catalog Item, you need to use
var mrvsJson = g_service_catalog.parent.getValue('temp_workers_for_create_accounts');
to get the existing values in your unfortunately-long-internal-name MRVS. It looks like you are using the MRVS 'name' variable to determine if a row for this worker already exists in the MRVS. I would do this onChange of this variable for a better user experience and immediate feedback/prevention of the new row before other data is needlessly entered.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
mrvsJson = g_service_catalog.parent.getValue('temp_workers_for_create_accounts');
if (mrvsJson.length > 2) { //native UI empty MRVS = '[]'
var obj = JSON.parse(mrvsJson);
for (var i = 0; i < obj.length; i++) {
if (obj[i].name == newValue) {
g_form.clearValue('name');
alert('Duplicate Temp Worker detected. This Temp Worker has already been added in the MRVS.);
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @JackieZhang ,
Try this:
function onSubmit() {
var result = [];
var items = [];
var getData = g_form.getValue('enter your mrvs name here'); //MultiRow Variable Set Name
getData = getData.toString().replace(/sys_id_of_the_variable/g, 'varibale_name'); //'variable_name' - Variable in MRVS.
var mrvData = JSON.parse(getData);
for (var i = 0; i < mrvData.length; i++) {
items.push(JSON.stringify(mrvData[i].varibale_name)); // varibale_name -->Variable in MRVS.
}
findDuplicateEntries(items);
if (result.length > 0) {
g_form.addErrorMessage("Please do not add the same item multiple times.");
return false;
}
function findDuplicateEntries(items) {
var sortElements = items.slice().sort();
for (var i = 0; i < sortElements.length - 1; i++) {
if (sortElements[i + 1] === sortElements[i]) {
result.push(sortElements[i]);
}
}
}
}I've found something similar in this link:
☆ Community Rising Star 22, 23 & 24 ☆
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Since this Catalog Client Script applies to the variable set, not the Catalog Item, you need to use
var mrvsJson = g_service_catalog.parent.getValue('temp_workers_for_create_accounts');
to get the existing values in your unfortunately-long-internal-name MRVS. It looks like you are using the MRVS 'name' variable to determine if a row for this worker already exists in the MRVS. I would do this onChange of this variable for a better user experience and immediate feedback/prevention of the new row before other data is needlessly entered.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
mrvsJson = g_service_catalog.parent.getValue('temp_workers_for_create_accounts');
if (mrvsJson.length > 2) { //native UI empty MRVS = '[]'
var obj = JSON.parse(mrvsJson);
for (var i = 0; i < obj.length; i++) {
if (obj[i].name == newValue) {
g_form.clearValue('name');
alert('Duplicate Temp Worker detected. This Temp Worker has already been added in the MRVS.);
}
}
}
}
