@kristian re: Rewriting the title - #32 by kristian
Hiya!! so the code has been working great! so thanks for that… but, I do have a question though… is there away of adding this…
e.g if “Pattern” attribute is “Floral” don’t add it to the title?
Hope that makes sense?
All the best
This seems to be possible by just adding
|| listing.attributes["Pattern"]=="Floral"
This is the new script:
function run() {
for (const listing of selectedListings) {
var thisBrand = "";
var thisSize = "";
var thisColour = "";
var thisPattern = "";
var thisFeatures = "";
var thisType = "";
if (!listing.attributes["Brand"] || listing.attributes["Brand"]=="") {
consoleLog("NO BRAND");
} else {
thisBrand = listing.attributes["Brand"] + " ";
}
if (!listing.attributes["Size"] || listing.attributes["Size"]=="") {
consoleLog("NO SIZE");
} else {
thisSize = "Size" + " " + listing.attributes["Size"] + " ";
}
if (!listing.attributes["Colour"] || listing.attributes["Colour"]=="") {
consoleLog("NO COLOUR");
} else {
thisColour = listing.attributes["Colour"] + " ";
}
if (!listing.attributes["Pattern"] || listing.attributes["Pattern"]=="" || listing.attributes["Pattern"]=="Floral") {
consoleLog("NO PATTERN");
} else {
thisPattern = listing.attributes["Pattern"] + " ";
}
if (!listing.attributes["Features"] || listing.attributes["Features"]=="") {
consoleLog("NO FEATURES");
} else {
thisFeatures = listing.attributes["Features"] + " ";
}
if (!listing.attributes["Type"] || listing.attributes["Type"]=="") {
consoleLog("NO TYPE");
} else {
thisType = listing.attributes["Type"] + " ";
}
listing.title = "Text" + " " + thisBrand + thisSize + thisColour + thisPattern + thisFeatures + thisType + "Text";
}
}
pkjack
July 8, 2022, 10:36am
3
Thats perfect!!! thanks again!
pkjack
July 17, 2022, 11:59am
4
Hey Kristian. 1 last question on this… Is there anyway to use an ‘if’ - with the same example… if pattern is floral then replace with “flowers” - again only the title… not actual attribute
All the best
This should do the trick:
function run() {
for (const listing of selectedListings) {
var thisBrand = "";
var thisSize = "";
var thisColour = "";
var thisPattern = "";
var thisFeatures = "";
var thisType = "";
if (!listing.attributes["Brand"] || listing.attributes["Brand"]=="") {
consoleLog("NO BRAND");
} else {
thisBrand = listing.attributes["Brand"] + " ";
}
if (!listing.attributes["Size"] || listing.attributes["Size"]=="") {
consoleLog("NO SIZE");
} else {
thisSize = "Size" + " " + listing.attributes["Size"] + " ";
}
if (!listing.attributes["Colour"] || listing.attributes["Colour"]=="") {
consoleLog("NO COLOUR");
} else {
thisColour = listing.attributes["Colour"] + " ";
}
if (!listing.attributes["Pattern"] || listing.attributes["Pattern"]=="") {
consoleLog("NO PATTERN");
} else {
if (listing.attributes["Pattern"]=="Floral") {
thisPattern = "Flower ";
} else {
thisPattern = listing.attributes["Pattern"] + " ";
}
}
if (!listing.attributes["Features"] || listing.attributes["Features"]=="") {
consoleLog("NO FEATURES");
} else {
thisFeatures = listing.attributes["Features"] + " ";
}
if (!listing.attributes["Type"] || listing.attributes["Type"]=="") {
consoleLog("NO TYPE");
} else {
thisType = listing.attributes["Type"] + " ";
}
listing.title = "Text" + " " + thisBrand + thisSize + thisColour + thisPattern + thisFeatures + thisType + "Text";
}
}
Regards, Kristian
system
Closed
July 28, 2022, 7:18am
6
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.