...
Code Block |
---|
|
let getUrl = values["Competitor Exact URL"]
function ExtractASIN(url){
var ASINreg = new RegExp(/(?:\/)([A-Z0-9]{10})(?:$|\/|\?)/)
var cMatch = url.match(ASINreg)
if(cMatch == null){
return null
}
return cMatch[1]
}
function ExtractCID(urls){
var CustomCID = new RegExp(/customId=([A-Za-z0-9]+)/)
var cMatch1 = (urls).match(CustomCID)
if(cMatch1 == null){
return null
}
return cMatch1[1]
}
function ExtractKeywords(url) {
const regex = /keywords=([^&]+)/;
const match = url.match(regex);
const keywords = match ? decodeURIComponent(match[1].replace(/\+/g, ' ')) : null;
return keywords.replace(/\+/g, ' ');;
}
this.changeFormValue("Comp_ASIN", ExtractASIN(getUrl))
if (ExtractCID(getUrl)== null){
this.changeFormValue("CustomID", "Not available")
}
else{
this.changeFormValue("CustomID", ExtractCID(getUrl))
}
if (ExtractKeywords(getUrl)== null){
this.changeFormValue("Source_Of_Search", "Not available")
}
else {
this.changeFormValue("Source_Of_Search", ExtractKeywords(getUrl))
} |
17. Generate rows in a name-value pair field
Code Block |
---|
|
let lineItems = []
let i = 0
/* To generate two empty rows */
while(i < 2) {
lineItems.push({
"weight": "",
"unit": ""
})
i += 1
}
/* Variant is the field name */
if(Array.isArray(lineItems)){
this.changeFormValue("Variant", JSON.stringify(lineItems))
} |