Good afternoon,
Having an issue with a fairly simple script. (This may/may not have something to do with me not knowing what I'm doing)
The script is laid out below, and basically looks for an image attached to an item, and if there is one, puts the URL on a custom column on a transaction form.
It is deployed when a transaction is saved, and we are using it on Sales Proposals.
It works fine, until you try to save a Sales Proposal with an Item Group on it. Then it returns Error: INVALID_RCRD_TYPE
Is it possible to reference an item group, or make the script ignore Item Groups?
I don't even care if we do a dodgy and override any errors, because there is nothing critical hanging on the script running.
Appreciate any contributions, thanks!
Cheers, Giles
SCRIPT:
function userEventBeforeSubmit(type){
var itemCount = nlapiGetLineItemCount('item');
for (var i=1;i<=itemCount;i++){
// get Item Id
var itemId = nlapiGetLineItemValue('item','item',i);
// get item type
var itemType = nlapiGetLineItemValue('item', 'itemtype', i);
var recordType = '';
switch (itemType) { // Compare item type to its record type counterpart
case 'InvtPart':
recordType = 'inventoryitem';
break;
case 'NonInvtPart':
recordType = 'noninventoryitem';
break;
case 'Service':
recordType = 'serviceitem';
break;
case 'Assembly':
recordType = 'assemblyitem';
break;
case 'GiftCert':
recordType = 'giftcertificateitem';
break;
default:
}
// load item and get image file from Item Display Thumbnail
var item = nlapiLoadRecord(recordType,itemId);
var imgFileId = item.getFieldValue('custitem_image');
// if it has image - continue
if (imgFileId) {
var file = nlapiLoadFile(imgFileId);
// printed file must be available without login, otherwise you get error on printing
if (file.isOnline()){
var imageUrl = file.getURL();
// complete url
var completeUrl = 'https://system.netsuite.com' + imageUrl;
// set completed url to your custom field of type free-form-text
nlapiSetLineItemValue('item','custcol_item_image_url',i,completeUrl);
}
}
}
}