This topic contains 8 replies, has 0 voices, and was last updated by david.smith 7 years, 7 months ago.
-
AuthorPosts
-
dmashburn3- Contributions: 0
- Level 1
- ☆
Hi 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. -
david.smith- Contributions: 0
- Level 1
- ☆
Use the name parameter.
Code:
function onFieldChange(type,name){
if(name=='custbody_containerbillcount' && nlapiGetFieldValue('custbody_containerbillcount') != ''){ -
dmashburn3- Contributions: 0
- Level 1
- ☆
Thanks David! Now all those samples I looked at make sense. I just needed someone to put it in some context.
-
dmashburn3- Contributions: 0
- Level 1
- ☆
Now 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? -
dmashburn3- Contributions: 0
- Level 1
- ☆
Also tried removing the second qualifier : nlapiGetFieldValue('custbody_containerbillcount') != ''
Same result
-
khultquist- Contributions: 0
- Level 1
- ☆
My 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');
}
}
} -
dmashburn3- Contributions: 0
- Level 1
- ☆
Interesting. 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. -
khultquist- Contributions: 0
- Level 1
- ☆
With your latest code, you're no longer checking for
nlapiGetFieldValue('custbody_containerbillcount') != ''
so that's probably the difference.
-
david.smith- Contributions: 0
- Level 1
- ☆
For 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.