Prevent duplicate entries being selected in a multi row variable set

matthew_hughes
Kilo Sage

I've got a multi row variable set that allows a user to select different AMA controls. However, what I've just noticed is that a user is able to select the same control twice for a Business Application.

Duplicate AMA controls.png

If the above example, the user should only select the 'Manual Order Process' AMA control only once. I was just wondering what I can do to stop the same AMA control being selected. A user should only select each AMA control once, not multiple times.

18 REPLIES 18

@matthew_hughes 

 

Can you update this 

From:
var value = parent.g_form.getValue("ama_controls"); // change mrvs name

 

TO 

var value = g_form.getValue("ama_controls"); // change mrvs name

The error is still occurring. This is my code:

OnSubmit client script.png

 

@matthew_hughes 

 

I have tried same script in my PDI and it worked really well

PrinceArora_0-1688141526388.png

 

I have used this script:

 

function onSubmit() {
var value = parent.g_form.getValue("ama_controls"); // change mrvs name
var arr = JSON.parse(value);

if (searchExisting(g_form.getValue("ama_control"), arr)) {
alert('There are duplicates please remove those before submitting');
return false;
}
}

function searchExisting(keyColumn, newArray) {
for (var i = 0; i < newArray.length; i++) {
if (newArray[i].ama_control == keyColumn) {
return true;
}
}
return false;
}

 

 

Please check your variable names are accurate!

Hi @Prince Arora Where are you putting that client script? Are you putting it within the 'Catalog Client Script' tab on the catalogue item or the Variable Set? When I click Submit, I'm getting the error message of 'There is a JavaScript error in your browser console'

@matthew_hughes 

 

Nope, this script has written on the variable set "client scripts".