Issue with List Collector Variable

pramodkumar
Tera Expert

Hi All,

I have a list collector variable on a catalog item referring to user table. When one user is selected, I am setting another variable in form. If list collector count is 1 , I am setting 1*10 and if 2, 2*10. It works as expected, when I remove one value from list, the other field is updated to 10 , when I remove another value in list (empty) the other variable value is not updating to 0. Any thoughts on this?

 

 

Thanks!

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

It sounds like you need help with a custom script, so it would help troubleshooting if you were to post the script.  Assuming you are using an onChange Catalog Client script, the standard template for new scripts includes this if statement at the beginning:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
...

which means the script does not run when the variable is empty, or the list collector does not have any records selected, in your case.  If you have this line, remove the or condition so that it's just

 if (isLoading) {

If you're still not getting the expected results, post your script and we'll get it sorted.

 

Thank you @Brad Bowman  

It is still not working. Please look at below script. I have added 2 users to list, then total is updated as 20 and when removed 1, total is updated as10. When removed the 1 user, total is still as 10


function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}

//Type appropriate comment here, and begin script below

var v1 = g_form.getValue('variable'); //list collector
var split = v1.split(',');
var length = split .length;
var v2= length * 10;
g_form.setValue('variable2',v2);
}

Since the script logic is working in all other test cases, it's likely having trouble trying to split an empty value or something like that, so you can code for this specific case:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    
    var v1 = g_form.getValue('variable'); //list collector
    if (!v1) { //list collector / v1 is empty
        g_form.setValue('variable2', '0');
    } else {
        var split = v1.split(',');
        var length = split .length;
        var v2= length * 10;
        g_form.setValue('variable2',v2);
    }
}