Jira code: UMAR-5
A suitelet page which allows the users to select the items to be added to the purchase requisition. User has to add the item, part description, part number, quantity, and unit. Then either go to the final stage of the vendor select by pressing the create requisitions button on that page. Otherwise, the user can go back to the vendor preview page.
Vendor Preview Page
Suitelet for Vendor Item Select Page
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/ui/serverWidget'],
function(serverWidget) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
function onRequest(context) {
var itemsForm = serverWidget.createForm({
title: 'Part Items Selection'
});
itemsForm.clientScriptFileId = 1608;
if(context.request.method =='GET'){
var jobId = context.request.parameters.custpage_jobid;
var jobField = itemsForm.addField({
id:'custpage_jobid',
type:serverWidget.FieldType.TEXT,
label: 'Job Id'
});
jobField.defaultValue = jobId;
jobField.updateDisplayType({
displayType : serverWidget.FieldDisplayType.DISABLED
});
jobField.updateDisplaySize({
height : 60,
width : 20
});
var loadingUrl = "https://system.eu2.netsuite.com/core/media/media.nl?id=2461&c=4817421&h=1461eeba51aacda4dba5";
//var loadingUrl = "https://system.eu1.netsuite.com/core/media/media.nl?id=1828&c=4817421_RP&h=cab4bd11ff379fc6c96c";
var image_tag = '<img id="custpage_load_img" style="height:80px;width:100px;visibility: hidden;" src="'+loadingUrl+'"/>';
var loadField = itemsForm.addField({
id:'custpage_progress',
type:serverWidget.FieldType.INLINEHTML,
label: 'Job Id'
});
loadField.defaultValue = image_tag;
loadField.updateLayoutType({
layoutType: serverWidget.FieldLayoutType.OUTSIDEBELOW
});
//Item List Table
var itemList = itemsForm.addSublist({
id:'part_items_list',
label: 'Add Part Items',
type:serverWidget.SublistType.INLINEEDITOR
});
//Item List Fields
itemList.addField({
id:'custrecord_netu_part_description',
label:'Part Description',
type:serverWidget.FieldType.TEXTAREA
});
itemList.addField({
id:'custrecord_netu_part_number',
label:'Part Number',
type:serverWidget.FieldType.TEXT
});
itemList.addField({
id:'custrecord_netu_parts_quantity',
label:'Quantity',
type:serverWidget.FieldType.FLOAT
});
itemList.addField({
id:'custrecord_netu_parts_unit',
label:'Unit',
source :'unitstype',
type:serverWidget.FieldType.SELECT
});
//Buttons
itemsForm.addButton({
id:'partItem_back',
label:'Back',
functionName:'moveBacktoPreview'
});
itemsForm.addSubmitButton({
label:'Create Requisitions',
});
}
context.response.writePage(itemsForm);
}
return {
onRequest: onRequest
};
});
Client Script
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord', 'N/record','N/search','./NetU_CS_Vendor_Library.js','N/url','N/https'],
function(currentRecord,record,search,vendorlib,url,https) {
function moveBacktoPreview(){
var record = currentRecord.get();
var jobId = record.getValue({
fieldId:'custpage_jobid'
});
var params ={};
params['custpage_jobid'] = jobId;
params['is_back'] =2;
var backUrl =url.resolveScript({
scriptId:'customscript_netu_vendor_select_preview',
deploymentId:'customdeploy_netu_vendor_select_preview',
returnExternalUrl:false,
params:params
});
if(window.onbeforeunload){
window.onbeforeunload = function(){null;};
}
window.location = backUrl;
}
/**
* Validation function to be executed when record is saved.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @returns {boolean} Return true if record is valid
*
* @since 2015.2
*/
function saveRecord(scriptContext) {
// to disable the 'Create Requisition' & 'Back' button
document.getElementById("partItem_back").disabled = true;
document.getElementById("submitter").disabled = true;
document.getElementById("custpage_load_img").style.visibility ='visible';
if(jQuery('#custpage_load_img').is(':visible')) {
var ACTION_CREATE_PART_ITEMS = 1;
var ACTION_CHECK_PART_EXISTANCE = 2;
var ACTION_CREATE_SUBJOBS =3;
var RESPONSE_EXISTS ='true';
var RESPONSE_NOT_EXISTS = 'false';
/*// to disable the 'Create Requisition' & 'Back' button
document.getElementById("partItem_back").disabled = true;
document.getElementById("submitter").disabled = true;*/
var itemRecord = scriptContext.currentRecord;
var jobId = itemRecord.getValue({
fieldId:'custpage_jobid'
});
// get all values and create the custom records for each items
var numLines = itemRecord.getLineCount({
sublistId: 'part_items_list'
});
console.log('itesm saveRecord---numlines--'+numLines);
var partsObjectArray =[];
var fieldArray =['custrecord_netu_part_description','custrecord_netu_part_number','custrecord_netu_parts_quantity','custrecord_netu_parts_unit'];
for(var index =0;index<numLines;index++){
var partsObj ={};
for(var i=0; i< fieldArray.length;i++){
var fieldKey = fieldArray[i];
var itemValue = itemRecord.getSublistValue({
sublistId: 'part_items_list',
line:index,
fieldId: fieldKey
});
partsObj[fieldKey]=itemValue;
}
partsObjectArray.push(partsObj);
}
var dataObj ={};
dataObj.jobId = jobId;
dataObj.parts_item = JSON.stringify(partsObjectArray);
executeServerActions(ACTION_CREATE_PART_ITEMS, dataObj);
dataObj.parts_item="";
var isPartsItemExists = executeServerActions(ACTION_CHECK_PART_EXISTANCE, dataObj);
console.log('isPartsItemExists '+isPartsItemExists);
if(isPartsItemExists == RESPONSE_NOT_EXISTS){
alert('Please enter part items to proceed');
// to Enable the 'Create Requisition' & 'Back' button
document.getElementById("partItem_back").disabled = false;
document.getElementById("submitter").disabled = false;
document.getElementById("custpage_load_img").style.visibility ='hidden';
return false;
}else{
var vendor_list = localStorage.getItem('vendor_select_record_str');
var itemCode = localStorage.getItem('itemCode');
var dataObj ={};
dataObj.jobId = jobId;
dataObj.vendor_list = vendor_list;
dataObj.itemCode = itemCode;
dataObj.isDirect = false;
dataObj.parts_item = JSON.stringify(partsObjectArray);
executeServerActions(ACTION_CREATE_SUBJOBS, dataObj);
var params = {};
params['custpage_jobid'] = jobId;
var nextUrl = url.resolveRecord({
recordType: 'customrecord_netu_main_job',
recordId: jobId,
isEditMode: false
});
if (window.onbeforeunload) {
window.onbeforeunload = function() {
null;
};
}
window.location = nextUrl;
}
}
//return false;
}
/**
* Execute Server side actions if
*/
function executeServerActions(action, dataObj){
var requestURL = url.resolveScript({
scriptId: 'customscript_netu_slb_main_job_wizard',
deploymentId: 'customdeploy_netu_slb_main_job_wizard',
returnExternalUrl: false
});
dataObj.action = action;
var body = JSON.stringify(dataObj);
var response = https.post({
url: requestURL,
body: body,
headers: {}
});
console.log('response--'+response.body);
return response.body;
}
return {
moveBacktoPreview: moveBacktoPreview,
saveRecord:saveRecord
};
});