Set Model Sticker Value in PO.

Jira Code: TC – 62

Set model sticker value from item record to the current line item in the purchase order when item is added to purchase order.

define([ 'N/record' ],
/**
 * @param {record}
 *            record
 */
function(record) {

	function pageInit(scriptContext) {

	}
	 function validateLine(context) {

			try {
				var objRecord = context.currentRecord;//get purchase order
				var itemId = objRecord.getCurrentSublistValue({//get current line item's id
					sublistId : 'item',
					fieldId : 'item'
				});

				var loaditem = record.load({   //load item record with id itemId
					type : 'inventoryitem',
					id : itemId,
					isDynamic : true,
				});
				var model_sticker = loaditem.getValue({ //get Model Sticker value from item record
					fieldId : 'custitem_rb_model_sticker_sour'
				});

				if (model_sticker != null && model_sticker != '') {// validate if empty
					try {				

						objRecord.setCurrentSublistValue({   //sets value from item record to purchase order line item
				                sublistId: 'item',
				                fieldId: 'custcol_model_stickers_new',
				                value: model_sticker.toString()
				            });			 					
						 
					} catch (e) {
						logme('e@set',getError(e));										
					}
				} else {

					try {						
						objRecord.setCurrentSublistValue({
			    			sublistId : 'item',
			    			fieldId : 'custcol_model_stickers_new',
			    			value : '0'
			    		});
						 
					} catch (e) {
						log.debug({
							title : 'e@model_stickerempty',
							details : e
						});
						
					}
				}
			} catch (e) {	
				alert(e);
				log.debug({
					title : 'e@sublistChanged',
					details : e
				});
				
			}
			 return true;
		
	 }

	/**
	 * Function to be executed after sublist is inserted, removed, or edited.
	 * 
	 * @param {Object}
	 *            scriptContext
	 * @param {Record}
	 *            scriptContext.currentRecord - Current form record
	 * @param {string}
	 *            scriptContext.sublistId - Sublist name
	 * 
	 * @since 2015.2
	 */
/*	function sublistChanged(scriptContext) {}*/

	return {
		pageInit : pageInit,		
		validateLine: validateLine	 
	};
	
	/*******************************************************************************
	 * return error
	 * 
	 * @param e
	 * @returns
	 * 
	 * Created on 09-Aug-2017 by rosemol
	 */
	function getError(e) {
		var stErrMsg = '';
		if (e.getDetails != undefined) {
			stErrMsg = '_' + e.getCode() + '<br>' + e.getDetails() + '<br>'
					+ e.getStackTrace();
		} else {
			stErrMsg = '_' + e.toString();
		}
		return stErrMsg;
	}

	/*******************************************************************************
	 * Log these data
	 * 
	 * @param title
	 * @param details
	 * @returns
	 * 
	 * Created on 09-Aug-2017 by rosemol
	 */
	function logme(title, details) {
		log.debug({
			title : title,
			details : details
		});

		console.log(title + " _ " + details);
	}
	

});

Leave a comment

Your email address will not be published. Required fields are marked *