Here is my validateListing() JavaScript script:
Neal
validateListing:
const newLine = ""; // "\n"
const blankLine = "\n"; // "\n\n"
function run() {
var errors = [];
var errorsCount = 0;
for (const listing of selectedListings) {
var validateErrors = validateListingProperties(listing);
if (validateErrors.length > 0) {
errorsCount++;
if (listing.title) {
errors.push(blankLine + "title: " + listing.title + ": " + newLine);
}
errors.push(... validateErrors);
}
}
consoleLog("selectedListings: " + selectedListings.length);
consoleLog("validateListing errors: " + errorsCount + newLine + errors + newLine);
}
function validateListing(listing) {
var errors = [];
var validateErrors = validateListingProperties(listing);
errors.push(... validateErrors);
return errors;
}
function validateListingProperties(listing) {
var errors = [];
var loopIndex = 1;
var listingTitle = "";
if (listing.title && (listing.title.length > 2)) {
listingTitle = listing.title;
}
if (listingTitle == "" /* !listing.title || (listing.title.length <= 2) */ ) {
errors.push("No Listing Title" + newLine);
}
if (listingTitle != "") {
if (listingTitle.indexOf(" ") >= 0) {
errors.push("title: " + listing.title + ": " + "<space><space>" + newLine);
}
if (listingTitle.startsWith(" ") || listingTitle.endsWith(" ")) {
errors.push("title: " + listing.title + ": " + "<space>" + newLine);
}
}
if (listing.subTitle && (listing.subTitle.length > 0)) {
errors.push("subTitle: " + listing.subTitle + newLine);
}
if (!listing.itemDescription || (listing.itemDescription.length <= 0)) {
// errors.push("No Listing Description" + newLine);
}
if (listing.itemDescription && (listing.itemDescription.length > 0)) {
if (listing.itemDescription.indexOf(" ") >= 0) {
errors.push("itemDescription: " + "<space><space><space>" + newLine);
}
}
if (listing.convertDescriptionToHTML) {
errors.push("convertDescriptionToHTML: " + listing.convertDescriptionToHTML + newLine);
}
if (listing.convertMarkdownToHTML) {
errors.push("convertMarkdownToHTML: " + listing.convertMarkdownToHTML + newLine);
}
if (listing.privateComment && (listing.privateComment.length > 0)) {
errors.push("privateComment: " + listing.privateComment + newLine);
}
if ((listing.siteID != 0) && (listing.siteID != 100)) { // eBay Motors
errors.push("siteID: " + listing.siteID + newLine);
}
if (listing.tag != 0) {
errors.push("tag: " + listing.tag + newLine);
}
if (listing.sku && (listing.sku.length > 0)) {
// errors.push("sku: " + listing.sku + newLine);
}
if (listing.conditionDescription && (listing.conditionDescription.length > 0)) {
errors.push("conditionDescription: " + listing.conditionDescription + newLine);
}
if (listing.isStoreListing) {
errors.push("isStoreListing: " + listing.isStoreListing + newLine);
}
if (listing.useLotSize) {
errors.push("useLotSize: " + listing.useLotSize + newLine);
}
if (listing.lotSize != 0) {
errors.push("lotSize: " + listing.lotSize + newLine);
}
if (listing.itemCost != 0) {
errors.push("itemCost: " + listing.itemCost + newLine);
}
if (!listing.useAutoPay) {
// errors.push("useAutoPay: " + listing.useAutoPay + newLine);
}
if (listing.useBuyItNowPrice && (listing.buyItNowPrice == 0)) {
errors.push("useBuyItNowPrice, buyItNowPrice: " + listing.useBuyItNowPrice + ", " + listing.buyItNowPrice + newLine);
}
if (listing.useReservePrice) {
errors.push("useReservePrice: " + listing.useReservePrice + newLine);
}
if (listing.reservePrice != 0) {
errors.push("reservePrice: " + listing.reservePrice + newLine);
}
if (listing.autoAcceptBestOffer) {
errors.push("autoAcceptBestOffer: " + listing.autoAcceptBestOffer + newLine);
}
if (listing.autoAcceptBestOfferPrice != 0) {
errors.push("autoAcceptBestOfferPrice: " + listing.autoAcceptBestOfferPrice + newLine);
}
if (listing.autoDeclineBestOffer) {
errors.push("autoDeclineBestOffer: " + listing.autoDeclineBestOffer + newLine);
}
if (listing.autoDeclineBestOfferPrice != 0) {
errors.push("autoDeclineBestOfferPrice: " + listing.autoDeclineBestOfferPrice + newLine);
}
if (listing.useVAT) {
errors.push("useVAT: " + useVAT + newLine);
}
if (listing.taxOrVatPercent != 0) {
errors.push("taxOrVatPercent: " + listing.taxOrVatPercent + newLine);
}
if (listing.paymentInstructions && (listing.paymentInstructions.length > 0)) {
errors.push("paymentInstructions: " + listing.paymentInstructions + newLine);
}
if (listing.productBarCode && (listing.productBarCode.length > 0)) {
if ((listing.productBarCode.length != 12) && (listing.productBarCode.length != 13)) { // && (listing.productBarCode != "Does not apply")
errors.push("productBarCode: " + listing.productBarCode + newLine);
}
}
if (listing.bidCount != 0) {
// errors.push("bidCount: " + listing.bidCount + newLine);
}
if (listing.taxOrVatPercent != 0) {
errors.push("taxOrVatPercent: " + listing.taxOrVatPercent + newLine);
}
if ((listing.duration != 7) && (listing.duration != 1000)) { // Use a value of 1000 to indicate a good-til-canceled (GTC) listing.
// errors.push("duration: " + listing.duration + newLine);
}
if (listing.handlingCost != 0) {
errors.push("handlingCost: " + listing.handlingCost + newLine);
}
var listingImageCount = 0;
if (listing.images) {
listingImageCount = listing.images.length;
}
if (listingImageCount == 0) {
errors.push("No Listing Images" + newLine);
}
loopIndex = 1;
for (const image of listing.images) {
if (loopIndex == 1) {
if (!image.isGalleryImage) {
errors.push("Image " + loopIndex + " " + "is NOT Gallery Image: " + image.isGalleryImage + newLine);
}
}
if (image.isGalleryImage) {
if (loopIndex != 1) {
errors.push("Image " + loopIndex + " " + "isGalleryImage: " + image.isGalleryImage + newLine);
}
}
if (image.caption && (image.caption.length > 0)) {
errors.push("Image " + loopIndex + " " + "caption: " + image.caption + newLine);
}
if (image.isURLImage) {
errors.push("Image " + loopIndex + " " + "isURLImage: " + image.isURLImage + newLine);
}
if (image.imageURL && (image.imageURL.length > 0)) {
errors.push("Image " + loopIndex + " " + "imageURL: " + image.imageURL + newLine);
}
loopIndex ++;
}
// consoleLog("validateListingProperties: " + errors);
return errors;
}
allListings:
function run() {
consoleLog("allListings: " + allListings.length);
consoleLog("selectedListings: " + selectedListings.length);
}
selectedListings:
function run() {
consoleLog("selectedListings: " + selectedListings.length);
for (const listing of selectedListings) {
consoleLog(listing.title);
}
}