Example situation: User wants to set item sublist of estimate page by importing item lines from different sales orders. So create a button in estimate page, “Import from sales orders”. By clicking that button will open a suitelet page.
In the suitelet page the user can select multiple sales order numbers. Then click on submit button in suitelet will redirect to estimate page. In the item sublist of estimate record user want to set the item lines of already selected sales order numbers from suitelet page. Normally item can be set by line by line. But if the item list contains any group item, then no need to set line by line. Need to set only the first line of group item.
For that, set a flag at zero. That is var itemgroupstart = 0
Then create a transaction saved search of sales order and get the value of item name and item type from search result. Then give condition to group item.
Example Code:
var itemgroupstart = 0;
var salesorderSearchObj = search.create({
type: "salesorder",
filters:
[
["type", "anyof", "SalesOrd"],
"AND",
["mainline", "is", "F"],
"AND",
["taxline", "is", "F"],
"AND",
["internalid", "anyof", sonumArray]
],
columns:
[
search.createColumn({name: "item", label: "Item"}),
search.createColumn({name: "itemtype", label: "itemType"})
]
});
var searchResultCount = salesorderSearchObj.runPaged().count;
salesorderSearchObj.run().each(function (result) {
// .run().each has a limit of 4,000 results
var item = result.getValue({
name: 'item'
});
var itemtype = result.getValue({
name: 'itemtype'
})
log.debug("itemtype",itemtype);
var detailsObj = {item:item}
if(itemgroupstart != 1)
var objArray = objR.push(detailsObj);
console.log("objArray:", objArray);
if(itemtype == "Group") {
itemgroupstart = 1;
}
if(itemtype == "EndGroup"){
itemgroupstart=0;
}
return true;
});
var len1 = objR.length;
for(var i = 0; i < len1; i++){
estRec = estRec.selectNewLine({
sublistId: 'item',
});
estRec = estRec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: objR[i].item,
forceSyncSourcing: true
});
estRec = estRec.commitLine({
sublistId: 'item'
});
}