Field changed function on Item Fulfillment for inventory detail - netsuite

I'm trying to copy the serial # from inventory detail on a Item Fulfillment line to another field for further processing, for which I'm trying to do a field changed function via Client Script but not able to figure out the field trigger.
This is what I have so far...
function populatePIF(type, name)
{
if(name == 'inventorydetail')
{
nlapiLogExecution('DEBUG', 'TEST', 'STATUS')
try
{
var inventorydetail = nlapiViewCurrentLineItemSubrecord('item', 'inventorydetail');
if(inventorydetail)
{
var PIF = inventorydetail.getCurrentLineItemText('inventoryassignment', 'issueinventorynumber');
nlapiSetCurrentLineItemValue('item', 'custcol_serial_no', PIF);
return true;
}
return true;
}
catch(e)
{
nlapiLogExecution('DEBUG', 'Exeception Caught', e);
}
return true;
}
}
Any ideas?

In my own recent experience, there is no trigger on the inventorydetail "field" as it's not really a field.
Line validation is also not triggered as far as I can tell.
Only option is an afterSubmit User event script. This will be more reliable.

Related

Netsuite AfterSubmit script creating customer

define ( ['N/record', 'N/ui/serverWidget', 'N/runtime','N/https'] ,// Add the callback function.function(record, serverWidget,runtime,https) {
// In the afterSubmit function, begin creating a task record.
function myAfterSubmit(context) {
var tgType = context.type;
if(tgType == 'create' || tgType == 'edit' || tgType == 'copy') {
var saleOrder = context.newRecord;
log.debug({title: 'Record Type ', details: context.newRecord.type });
if (saleOrder.type == "salesorder" )
{
var uniqueKey = saleOrder.id
log.debug("uniquekey",uniqueKey)
}
else
{
log.debug("error",'No data found')
}
}
return {
afterSubmit: myAfterSubmit
};
});
Hello Netsuite experts,
I am looking for solution to access created customer's info with aftersubmit function of userevernt script.
salesorder is working well
Tried "customer" and it's not triggering to the script.
Thanks!
Do You want created customer's internal id in your script? if yes,
here is the code, in after submit for edit mode you need to use oldRecord
otherwise for newly created use newRecord(on create/copy mode and load the record). and deploy it on customer record as well.
function myAfterSubmit(context) {
var tgType = context.type;
if(tgType == 'create' || tgType == 'edit' || tgType == 'copy') {
var rec= context.oldRecord;
log.debug({title: 'Record Type ', details: context.oldRecord.type });
if (rec.type == "customer" )
{
var customerIntId= rec.id
log.debug("customerIntId",customerIntId)
}**strong text**
else
{
log.debug("error",'No data found')
}
}

How to make sublist field mandatory?

This is my pageInit function
function poTransPageInit(type) {
// alert('page init');
var field= nlapiGetLineItemField('item', 'field');
field.isMandatory = true;
}
what I do wrong here?
It is true that the isMandatory method is not available in Client Scripts. As a work around you could get the field's value and check the length.
function validateLine(type){
if(type == 'sublistInternalID'){ //sublistInternalID = sublist internal id, i.e. 'item'
//get the sublist field value of mandatory column
var name = nlapiGetCurrentLineItemValue('line', 'fieldId'); //line = line #, fieldId = internal id of field
//if value length is greater than 0, then there is a value
if(name.length > 0){
return true;
} else {
alert('Please enter a value for Name field');
return false;
}
}
}
field.isMandatory is SuiteScript 2.0. In SuiteScript 1.0, you would use field.setMandatory(true), but apparently that function is not available in client scripts.
You could try moving this logic to a User Event script.

How to set a column field on a Journal entry to false

I am trying to set a mandatory column field(through UI at field level) to false on a Journal Entry record.
I need to use User Event script because the journal entries are system generated and the same custom field should be mandatory for other transactions.
I have tried using a user event before load and setMandatory(false) but it is not working.
Here is the code I am using:
function removeMandatory(type)
{
if(type == 'create')
{
for( var i =1 ; i < nlapiGetLineItemCount('line') ; i++)
{
var customField = nlapiGetLineItemField('line', 'custcol_test_mandatory', i);
customField.setMandatory(false);
}
}
}
Any help is appreciated, Thanks
Thanks #Rusty Shackles:
I have actually worked it out using User Event Before Load function. Here is the code:
function notMandatoryBeforeLoad(type)
{
var context = nlapiGetContext();
if(type == 'create' && context.getExecutionContext() == 'scheduled')
{
var LineMandatoryField = nlapiGetLineItemField('line','custcol_test_mandatory');
if (LineMandatoryField)
{
LineMandatoryField.setMandatory(false);
}
}
}
I believe field objects are read only if not done in a Suitelet.
What you can do is use a client side script that executes on field change/validate field and check if the "mandatory" field as a value.

mocking the populate method using mockgoose for mongoose (mongodb library for node.js) is null

Having trouble debugging an issue that mockgoose has for populating a property with fields set. Yads mockgoose http://github.com/yads/Mockgoose fork solved the bug of making the populate option work, but if you specify fields it returns a null for the populated property. I tried looking through the source code and stepping through with the debugger but not sure where to look. I can see in the debugger that the populate option triggers a call to get the child element - and I see the call made returns the right child result with the correct fields, but when the parent element finally comes back it has the property to the child element set to null.
The query:
Posts.findById(foo).populate('createdBy', {fname:1, lname:1});
Incorrectly returns a post with post.createdBy = null. Omitting the fields parameter of fame, lname, somehow makes it work again with post.createdBy returning the full object.
Following are some excerpts from the code - though I'm not sure those are the right places to look.
collections.js
this.find = function (conditions, options, callback) {
var results;
var models = db[name];
if (!_.isEmpty(conditions)) {
results = utils.findModelQuery(models, conditions);
} else {
results = utils.objectToArray(utils.cloneItems(models));
}
results = filter.applyOptions(options, results);
if (results.name === 'MongoError') {
callback(results);
} else {
var result = {
toArray: function (callback) {
callback(null, results);
}
};
callback(null, result);
}
};
util.js
function cloneItems(items) {
var clones = {};
for (var item in items) {
clones[item] = cloneItem(items[item]);
}
return clones;
}
function cloneItem(item) {
return _.cloneDeep(item, function(value) {
// Do not clone items that are ObjectId objects as _.clone mangles them
if (value instanceof ObjectId) {
return new ObjectId(value.toString());
}
});
}
And here's a conversation about the issue
https://github.com/mccormicka/Mockgoose/pull/90

[HMVC??] Call Functions in another controller and get values

I am facing a situation where I need to call a function to check some status.
$lastupdate=Request::factory('user/getlastupdate/'.$userid.'')->execute();
My getlastupdate function looks like this:
public function action_getlastupdate($userid){
$status=array();
try{
$updatestatus= ORM::factory('updates')
->where('id', '=', $userid)
->where('deleted', '=',0)
->find_all();
//check if result returned values
$resultcount=count($updatestatus);
//if result has data
if($resultcount>0){
foreach($updatestatus as $status)
{
$stat="found";
$result= 'Profile Last Updated on'.$updatestatus->lastupdate;
}
}//end if result has data
//if record returned no values
else{
$stat="missing";
$result= 'Profile Data Missing';
}//end if resultcount>0
}//end try
catch(ORM_Validation_Exception $e)
{
$stat="error";
$result="Profile Update Search Error ".$e->errors('updates');
}///end catch
$status['result']=$result;
$status['stat']=$stat;
$this->response->body(View::factory('pages/updatestatus', $status));
}//end function
This works but I do not want to render the view. I want to return the array status and use it from within my controller which is calling this method. How can I implement this? Does the code change if I call from the same controller vis a vis calling from a different controller?
I am using kostache templates so I need to play with the status[values] before rendering final output to my view.
You could send an extra parameter for your subquery which will indicate whether to auto render the view or not.
$lastupdate=Request::factory('user/getlastupdate/'.$userid.'/off')->execute();
and in your action getlastupdate check the parameter
action_getlastupdate($userid, $renderView = '')
{
if( $renderView === 'off' )
{
$this->auto_render = FALSE;
}
[...]
}

Resources