Jira code: BLUEL-19
The vendor needs the permission to update the Promise Date on PO. No need to edit other fields. For vendors restricted the purchase order permission to view level. The vendor can only view the purchase order with status pending receipt, partially received, partially received/pending billing.
When the PO status is ‘pending approval’ user should return an error. Created a workflow to return an error message to vendors when PO status is ‘pending approval’. Created a new tab for vendor role and added the suitelet page.
User event script:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/**
* Script Description
* In PO, for vendor we have given an access for viewing PO. When a vendor enter NS from the given role when the PO status
* Approved by Supervisor/Pending Receipt,Pending Received,Pending Billing/Partially Received,Pending Bill,Pending Receipt
* an 'EDIT' button will be visible , on click we will redirect to tyhe suitelet page
*
*/
/*******************************************************************************
* CORP DESIGN
* **************************************************************************
*
* Date: 24/05/2019
*
* Author: Jobin & Jismi IT Services LLP
*
*
* REVISION HISTORY
*
* Revision $ 24/05/2019 Maria: Create
*
******************************************************************************/
define(['N/record','N/runtime','N/search'],
function(record,runtime,search) {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type
* @param {Form} scriptContext.form - Current form
* @Since 2015.2
*/
function beforeLoad(scriptContext) {
try{
var SO_id = scriptContext.newRecord.id;
var CustRec=scriptContext.form;
var userObj = runtime.getCurrentUser();
var userRole = runtime.getCurrentUser().role;
//When the role is BLUEL Vendor Center
if(userRole == 1061){
var PO_status = scriptContext.newRecord.getValue({
fieldId: 'status'
});
//search to get PO status
var purchaseorderSearchObj = search.create({
type: "purchaseorder",
filters:
[
["type","anyof","PurchOrd"],
"AND",
["status","anyof","PurchOrd:D","PurchOrd:F","PurchOrd:E","PurchOrd:B"],
"AND",
["internalidnumber","equalto",SO_id],
"AND",
["mainline","is","T"]
],
columns:
[
search.createColumn({
name: "ordertype",
sort: search.Sort.ASC,
label: "Order Type"
}),
search.createColumn({name: "internalid", label: "Internal ID"})
]
});
var searchResultCount = purchaseorderSearchObj.runPaged().count;
log.debug("purchaseorderSearchObj result count",searchResultCount);
//If PO has the following status
if(searchResultCount > 0){
CustRec.clientScriptFileId = 1763828;
//Setting the button to redirect to suitelet page
var PO_editbutton = CustRec.addButton({
id:'custpage_edit_button',
label:'Edit',
functionName:'purchaseorderedit'
});
}
}
}catch (e) {
logme("error@beforeLoad", getError(e));
}
}
/*******************************************************************************
* return error
*
* @param e
* @returns
*
* Created on 14-May-2019 by Maria
*/
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 14-May-2019 by Maria
*/
function logme(title, details) {
log.debug({
title : title,
details : details
});
}
return {
beforeLoad: beforeLoad
//beforeSubmit: beforeSubmit,
//afterSubmit: afterSubmit
};
})
Client Script:-
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/**
* Script Description
* In PO, on the 'BLUEL Vendor Center' role, edit button shows, on click redirect to the suitelet form.
.
*
*/
/*******************************************************************************
* CORP DESIGN
* **************************************************************************
*
* Date: 24/05/2019
*
* Author: Jobin & Jismi IT Services LLP
*
*
* REVISION HISTORY
*
* Revision $ 24/05/2019 Maria: Create
*
******************************************************************************/
define(['N/currentRecord','N/email','N/runtime','N/record','N/search','N/url','N/https'],
function(currentRecord,email,runtime,record,search,url,https) {
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
function pageInit(scriptContext) {
}
/**
* Function to be executed on Edit button click.
*
*/
function purchaseorderedit(){
try{
var currentRec = currentRecord.get();
var recid = currentRec.id;
console.log("recid",recid);
//Setting the url of the suitelet script
var output = url.resolveScript({
scriptId: 'customscript_bluel22_sl_vendor_access',
deploymentId: 'customdeploy_bluel22_sl_vendor_access',
returnExternalUrl: false,
})+ '&poid='+recid;
console.log("output",output);
window.open(output);
}catch (e) {
logme("error@beforeLoad", getError(e));
}
}
/*******************************************************************************
* return error
*
* @param e
* @returns
*
* Created on 14-May-2019 by Maria
*/
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 14-May-2019 by Maria
*/
function logme(title, details) {
log.debug({
title : title,
details : details
});
}
return {
pageInit: pageInit,
purchaseorderedit: purchaseorderedit
/*fieldChanged: fieldChanged,
postSourcing: postSourcing,
sublistChanged: sublistChanged,
lineInit: lineInit,
validateField: validateField,
validateLine: validateLine,
validateInsert: validateInsert,
validateDelete: validateDelete,
saveRecord: saveRecord*/
};
});