We update a file in the file cabinet based on the items that modified yesterday. This file URL is used in the Bronto to update the Product feeds. Script Scheduled to run at 7 am each day and Bronto update on 8 am based on the file.
/**
* @NApiVersion 2.0
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
/**
* Script Description
* This schedule script to a file in the file cabinet based on the items update in the last day.
*/
/*******************************************************************************
*
* NetSuite Name :SCL-11 SS Item Search Create File
* Script ID :customscript_jj_scl_11_sl_item_file
*
* *****************************************************************************
*
*
* $Author: Jobin & Jismi IT Services LLP $
*
* DESCRIPTION
* We update a file in the filecabinet based on the items that modified yesterday.
* This file URL is used in the Bronto to update the Product feeds.
* Script Scheduled to run at 7am each day and Bronto update on 8am based on the file.
*
* Date Created :12-11-2019
*
* REVISION HISTORY Update:
*
*
*
******************************************************************************/
define(['N/search', 'N/runtime', 'N/record', 'N/https', 'N/file', 'N/ui/serverWidget', 'N/email'],
function (search, runtime, record, https, file, serverWidget, email) {
var main = {
execute: function (context) {
var myXMLFile = file.load({
id: '82066'
});
var xmlContent = myXMLFile.getContents();
var strVar = "";
var itemSearchObj = search.create({
type: "item",
filters: [
["type", "anyof", "Assembly", "Description", "Discount", "GiftCert", "InvtPart", "Group", "Markup", "Kit", "Subtotal", "Service", "OthCharge", "Payment", "NonInvtPart"],
"AND",
["upccode", "isnotempty", ""],
"AND",
["modified", "on", "yesterday"],
"AND",
["name", "isnotempty", ""],
"AND",
["description", "isnotempty", ""]
],
columns: [
search.createColumn({
name: "itemid",
label: "Product Id"
}),
search.createColumn({
name: "type",
label: "Type"
}),
search.createColumn({
name: "internalid",
label: "Internal ID"
}),
search.createColumn({
name: "upccode",
sort: search.Sort.ASC,
label: "UPC Code"
}),
search.createColumn({
name: "salesdescription",
label: "Description"
}),
search.createColumn({
name: "custitem_matrix_color",
label: "Matrix Color"
}),
search.createColumn({
name: "custitem_specfeatures",
label: "Special features"
}),
search.createColumn({
name: "custitem_gold",
label: "Gold"
}),
search.createColumn({
name: "custitem_colors",
label: "Gold Color"
}),
search.createColumn({
name: "custitem3",
label: "Brand"
})
]
});
var searchResultCount = itemSearchObj.runPaged().count;
log.debug("itemSearchObj result count", searchResultCount);
itemSearchObj.run().each(function (result) {
var productId = result.getValue({
name: "itemid",
label: "Product Id"
})
var type = result.getValue({
name: "type",
label: "Type"
})
var upccode = result.getValue({
name: "upccode",
sort: search.Sort.ASC,
label: "UPC Code"
})
var salesdescription = result.getValue({
name: "salesdescription",
label: "Description"
})
if (!salesdescription) {
var salesdescription = result[i].getValue({
name: "displayname",
label: "Display Name"
})
}
var matrix_color = result.getText({
name: "custitem_matrix_color",
label: "Matrix Color"
})
var specfeatures = result.getValue({
name: "custitem_specfeatures",
label: "Special features"
})
var gold = result.getText({
name: "custitem_gold",
label: "Gold"
})
var goldcolors = result.getText({
name: "custitem_colors",
label: "Gold Color"
})
var brand = result.getValue({
name: "custitem3",
label: "Brand"
})
strVar += "<item>";
strVar += "<ProductId>" + productId + "</ProductId>";
strVar += "<Description>" + salesdescription + "</Description>";
strVar += "<UPC_CODE>" + upccode + "</UPC_CODE>";
strVar += "<colour>" + matrix_color + "</colour>";
strVar += "<Brand>" + brand + "</Brand>";
strVar += "<Gold>" + gold + "</Gold>";
strVar += "<GoldColor>" + goldcolors + "</GoldColor>";
strVar += "<Specialfeatures>" + specfeatures + "</Specialfeatures>";
strVar += "<Type>" + type + "</Type>";
strVar += "</item>";
strVar = strVar + '\n';
return true;
});
xmlContent = xmlContent.replace("<!-- REPLACEITEM -->", strVar);
xmlContent = xmlContent.replace(/&/g, '&');
var filearray = file.create({
name: 'Item to Product Feed.xml',
fileType: file.Type.PLAINTEXT,
contents: xmlContent,
folder: 20917,
isOnline: true
});
var filearrayid = filearray.save();
}
}
for (var key in main) {
if (typeof main[key] === 'function') {
main[key] = trycatch(main[key], key);
}
}
function trycatch(myfunction, key) {
return function () {
try {
return myfunction.apply(this, arguments);
} catch (e) {
log.debug("e in " + key, e);
}
}
};
return main;
});