When exactly does a validation script trigger?

So as an experiment, I’ve created this “validation” script, as a framework to experiment with side-effect incrementing a User property called CBLAUNCHCOUNT.

One of the things I’ve noticed about it: it runs once (and increments the value) when I select the listings to launch them manually, and it also runs when they are launched. So every time I stop and launch listings, the number goes up by 2, not 1 as expected.

Aside from enabling/disabling the validator in the middle of the stop-start manual task, is there a way to have it trigger only when the listing is actually launched (successfully) on eBay?

function validateListing(listing) {
  
    var userProps = listing.userProperties;
    let count = parseInt(userProps["CBLAUNCHCOUNT"]) + 1;
    userProps["CBLAUNCHCOUNT"] = count.toString();
    listing.userProperties = userProps;
        
    errors = [];
    return errors;
}

Actually now I’m not 100% sure this is running twice. I will need to reset the value and check.

But the original question remains, in a slightly different form: Is there a way for me to trigger this increment side-effect after the validations themselves have happened? I assume that GarageSale is invoking whatever script is called validateListing(listing) and expecting an errors array as a result returned from the function. The return stops execution in Javascript, so obviously the increment can’t occur after that final line.

I suppose I could move the four lines fiddling the user properties into a function, and wrap that function call in a conditional depending on whether errors is empty.

1 Like

I don’t want to make any guarantees when and how often the validateListing hook gets invoked for each listing.

What about separate JavaScript callbacks that get invoked when a listing was just listed or re-listed? Sounds more reliable to me. :thinking:

1 Like

If it’s able to detect successful listing or delisting, that would be awesome, though it also sounds like it would take a new UI of some sort? I’m a little concerned about hanging little scripts off all the hooks and the whole tree catching fire :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.