This topic contains 8 replies, has 0 voices, and was last updated by david.smith 7 years, 9 months ago.
-
AuthorPosts
-
February 1, 2017 at 8:44 am #21889
dmashburn3Hi Everyone,
I'm trying to use this field change trigger for the first time. I've run into a situation where it is performing the action I desire, however, I have a prompt inside the script that ends up popping up continuously.
Code:
function onFieldChange(type,name){
if(nlapiGetFieldValue('custbody_containerbillcount') != ''){
var totalBillAmount = nlapiGetFieldValue('usertotal');
var containerCount = nlapiGetFieldValue('custbody_containerbillcount');
var memoField = nlapiGetLineItemValue('expense','memo',1);
var x = confirm("Do you want to split bill amount of "+ totalBillAmount + " into "+ containerCount + " line items.");
if( x == true){
for(var j = 1; j <= containerCount; j++){
nlapiLogExecution('debug','Details','j = '+j);
nlapiSelectLineItem('expense',j);
nlapiSetCurrentLineItemValue('expense','account',487);
nlapiSetCurrentLineItemValue('expense','amount',parseFloat(totalBillAmount)/parseInt(containerCount));
nlapiSetCurrentLineItemValue('expense','memo',memoField);
nlapiSetCurrentLineItemValue('expense','class',45);
nlapiSetCurrentLineItemValue('expense','department',1);
nlapiSetCurrentLineItemValue('expense','location',1)
nlapiCommitLineItem('expense');
}
} else {
alert('Action cancelled');
}
}
}
When I change the field value custbody_containerbillcount it successfully prompts for the action, I click ok, it manipulates my lines, but then it prompts again.I assume this is because the script is still sitting there and seeing that the initial if condition is met? In which case, how do I write a condition for a field to have a number entered, but then exit once the actions are complete?
Thanks
This is a cached copy. Click here to see the original post. -
February 1, 2017 at 9:11 am #21890
david.smithUse the name parameter.
Code:
function onFieldChange(type,name){
if(name=='custbody_containerbillcount' && nlapiGetFieldValue('custbody_containerbillcount') != ''){ -
February 1, 2017 at 9:13 am #21891
dmashburn3Thanks David! Now all those samples I looked at make sense. I just needed someone to put it in some context.
-
February 1, 2017 at 10:39 am #21892
dmashburn3Now my script actually isn't doing any of my actions. It can't seem to get past the if statement.
Code:
function onFieldChange(name){
nlapiLogExecution('debug','Details','Test1');
if (name == 'custbody_containerbillcount' && nlapiGetFieldValue('custbody_containerbillcount') != ''){
nlapiLogExecution('debug','Details','Test2');
var totalBillAmount = nlapiGetFieldValue('usertotal');
var containerCount = nlapiGetFieldValue('custbody_containerbillcount');
var memoField = nlapiGetLineItemValue('expense','memo',1);
var x = confirm("Do you want to split bill amount of "+ totalBillAmount + " into "+ containerCount + " line items.");
if( x == true){
for(var j = 1; j <= containerCount; j++){
nlapiLogExecution('debug','Details','j = '+j);
nlapiSelectLineItem('expense',j);
nlapiSetCurrentLineItemValue('expense','account',487);
nlapiSetCurrentLineItemValue('expense','amount',parseFloat(totalBillAmount)/parseInt(containerCount));
nlapiSetCurrentLineItemValue('expense','memo',memoField);
nlapiSetCurrentLineItemValue('expense','class',45);
nlapiSetCurrentLineItemValue('expense','department',1);
nlapiSetCurrentLineItemValue('expense','location',1)
nlapiCommitLineItem('expense');
}
} else {
alert('Action cancelled');
}
}
}
Execution log shows Test1 when the page is loaded, as well as another log when the line is changed, however it is not showing Test2? -
February 1, 2017 at 10:41 am #21893
dmashburn3Also tried removing the second qualifier : nlapiGetFieldValue('custbody_containerbillcount') != ''
Same result
-
February 1, 2017 at 11:18 am #21894
khultquistMy guess is that nlapiGetFieldValue('custbody_containerbillcount') is NULL, but debug it like this:
Code:
function onFieldChange(name){
var containerbillcount = nlapiGetFieldValue('custbody_containerbillcount');
nlapiLogExecution('debug', 'name', name);
nlapiLogExecution('debug', 'containerbillcount', containerbillcount);
if (name == 'custbody_containerbillcount' && containerbillcount != ''){
nlapiLogExecution('debug','Details','Test2');
var totalBillAmount = nlapiGetFieldValue('usertotal');
var containerCount = nlapiGetFieldValue('custbody_containerbillcount');
var memoField = nlapiGetLineItemValue('expense','memo',1);
var x = confirm("Do you want to split bill amount of "+ totalBillAmount + " into "+ containerCount + " line items.");
if( x == true){
for(var j = 1; j <= containerCount; j++){
nlapiLogExecution('debug','Details','j = '+j);
nlapiSelectLineItem('expense',j);
nlapiSetCurrentLineItemValue('expense','account',487);
nlapiSetCurrentLineItemValue('expense','amount',parseFloat(totalBillAmount)/parseInt(containerCount));
nlapiSetCurrentLineItemValue('expense','memo',memoField);
nlapiSetCurrentLineItemValue('expense','class',45);
nlapiSetCurrentLineItemValue('expense','department',1);
nlapiSetCurrentLineItemValue('expense','location',1)
nlapiCommitLineItem('expense');
}
} else {
alert('Action cancelled');
}
}
} -
February 1, 2017 at 11:34 am #21895
dmashburn3Interesting. The name is debugging 3 times on the page load.
Debug
containerbillcount
2/1/2017
1:29 pm
Danny MashburnRemove
View
Debug
name
2/1/2017
1:29 pm
Danny Mashburn
landedcostsource5
RemoveView
Debug
Details
2/1/2017
1:29 pm
Danny Mashburn
Test1
RemoveView
Debug
containerbillcount
2/1/2017
1:29 pm
Danny MashburnRemove
View
Debug
name
2/1/2017
1:29 pm
Danny Mashburn
landedcostsource3
RemoveView
Debug
Details
2/1/2017
1:29 pm
Danny Mashburn
Test1
RemoveView
Debug
containerbillcount
2/1/2017
1:29 pm
Danny MashburnRemove
View
Debug
name
2/1/2017
1:29 pm
Danny Mashburn
landedcostsource2
RemoveView
Debug
Details
2/1/2017
1:29 pm
Danny Mashburn
Test1
RemoveSorry for the table view, the image upload seems to be calling all my files corrupted.
That's before I even try to edit the field. Any ideas?
Also, I did get the script to work by passing the manipulations down into another function like this:
Code:
function onFieldChange(type, name){
nlapiLogExecution('debug','Details','Test1');
var containerbillcount = nlapiGetFieldValue('custbody_containerbillcount');
nlapiLogExecution('debug', 'name', name);
nlapiLogExecution('debug', 'containerbillcount', containerbillcount);
if (name === 'custbody_containerbillcount'){
doThis();
}
}function doThis(){
nlapiLogExecution('debug','Details','Test3');
var totalBillAmount = nlapiGetFieldValue('usertotal');
var containerCount = nlapiGetFieldValue('custbody_containerbillcount');
var memoField = nlapiGetLineItemValue('expense','memo',1);
var x = confirm("Do you want to split bill amount of "+ totalBillAmount + " into "+ containerCount + " line items.");
if( x == true){
for(var j = 1; j <= containerCount; j++){
nlapiLogExecution('debug','Details','j = '+j);
nlapiSelectLineItem('expense',j);
nlapiSetCurrentLineItemValue('expense','account',487);
nlapiSetCurrentLineItemValue('expense','amount',parseFloat(totalBillAmount)/parseInt(containerCount));
nlapiSetCurrentLineItemValue('expense','memo',memoField);
nlapiSetCurrentLineItemValue('expense','class',45);
nlapiSetCurrentLineItemValue('expense','department',1);
nlapiSetCurrentLineItemValue('expense','location',1)
nlapiCommitLineItem('expense');
}
} else {
alert('Action cancelled');
}
}
I don't really know why this works, and I'm curious about the landedcostsource2,3,5 but for now its working at least. -
February 1, 2017 at 12:03 pm #21896
khultquistWith your latest code, you're no longer checking for
nlapiGetFieldValue('custbody_containerbillcount') != ''
so that's probably the difference.
-
February 2, 2017 at 8:55 am #21897
david.smithFor client scripts I like to use the console for debugging rather than constantly switching tabs to see the script logs. You can also perform most of you code directly in the console to see the values.
ironside replied on 02/23/2017, 10:36 PM: side note: If one uses NFT, you get console logging by default for any client script, server logging by default for server-side scripts.
-
AuthorPosts
You must be logged in to reply to this topic.