@pkjack contacted me through the support with some request regarding adding certain attributes to the title so I tried to create one based on @Vaguery script. It might be helpful for others, too, that’s why I am posting it here. Feel free to modify and improve it to fit your needs.
function run() {
var thisBrand = "";
var thisSize = "";
var thisColour = "";
var thisPattern = "";
var thisFeatures = "";
var thisType = "";
for (const listing of selectedListings) {
if (!listing.attributes["Brand"]) {
consoleLog("NO BRAND");
} else {
thisBrand = listing.attributes["Brand"] + " ";
}
if (!listing.attributes["Size"]) {
consoleLog("NO SIZE");
} else {
thisSize = "Size" + " " + listing.attributes["Size"] + " ";
}
if (!listing.attributes["Colour"]) {
consoleLog("NO COLOUR");
} else {
thisColour = listing.attributes["Colour"] + " ";
}
if (!listing.attributes["Pattern"]) {
consoleLog("NO PATTERN");
} else {
thisPattern = listing.attributes["Pattern"] + " ";
}
if (!listing.attributes["Features"]) {
consoleLog("NO FEATURES");
} else {
thisFeatures = listing.attributes["Features"] + " ";
}
if (!listing.attributes["Type"]) {
consoleLog("NO TYPE");
} else {
thisType = listing.attributes["Type"] + " ";
}
listing.title = "Text" + " " + thisBrand + thisSize + thisColour + thisPattern + thisFeatures + thisType + "Text";
}
}
The problem i had was if a attribute was missing it would read as undefined - this is where @Vaguery 2nd solution come into play with removing anything that was blank… but i could quite figure out how to implement into each other…
If pattern attribute is there but is blank… it leaves a space… is there anyway around that? I use a template lsiting to duplicate so have all the options…
Yeah i did try… let me try again. been doing so much copy & pasting my head feels like its melting…
Should this work on when slecting more than 1 item right?
I seem to have this problem say i select 10 items… it adds a random " pattern " into the title even though the item doesnt have a pattern attribute at all…?