This topic contains 8 replies, has 0 voices, and was last updated by darrenhillconsulting 7 years, 10 months ago.
-
AuthorPosts
-
January 5, 2017 at 6:58 am #1339
peterbellHi all
I am hoping someone can help me.
I have a custom record on my account that logs scores from a web form. These are all held in individual Integer Number fields and I want to create an average score with my script based on the number of answers given.
Being SuiteScript2.0 I was under the impression that the data type should be consistent with the field type so that the getValue for these integer fields will already be a number type, however this does not seem to be the case. I have logged various parts of this script and the getValue is working (for example I set the field value of ‘custrecord_cs15_inc_everything’ to 8, and it logs 8 for quoteIncludeAll), bit when I get to the if(xxxxxxxx > 0) bit it doesnt recognise this as a number so the ‘if’ is always false.
I have tried Number() to force the values to be numbers, but it throws an error when I try to set the value at the end of the code.
Here is a sample of my script:
Code:
var quoteDenom = 0;
var quoteIncludeAll = surveyRecord.getValue(‘custrecord_cs15_inc_everything’);
if (quoteIncludeAll > 0){
quoteDenom++;
}
var quotedQuick = surveyRecord.getValue(‘custrecord_cs15_quote_quick’);
if (quotedQuick > 0){
quoteDenom++;
}
var easyToUnderstand = surveyRecord.getValue(‘custrecord_cs15_easy_understand’);
if (easyToUnderstand > 0){
quoteDenom++;
}
if (quoteDenom >= 1){
var quoteAverage = twoDP((quoteIncludeAll + quotedQuick + easyToUnderstand)/quoteDenom);
surveyRecord.setValue(‘custrecord_cs15_quote_average’,quoteAverage);
}
Any help would be appreciatedPeter
This is a cached copy. Click here to see the original post. -
January 5, 2017 at 8:03 am #1340
Olivier Gagnon NCHi Peter,
Use parseInt(value)
Cheers
-
January 5, 2017 at 8:42 am #1341
peterbellOriginally posted by Olivier Gagnon NC
View Post
Hi Peter,
Use parseInt(value)
Cheers
Hi Olivier
Thanks for your help
It is really strange – when I us surveyRecord.getValue(‘custrecord_cs15_understood_ project’) without Number() or parseInt() I get the value for the field. As soon as I add either of those ie parseInt(surveyRecord.getValue(‘custrecord_cs15_un derstood_project’)) I get nothing at all.
borncorp replied on 01/05/2017, 07:20 PM: check if the variable names are correct, you have “custrecord_cs15_un derstood_project” instead of “custrecord_cs15_understood_ project”
-
January 5, 2017 at 9:02 am #1342
Olivier Gagnon NCErrr… that IS quite odd. parseInt as an optional secondary param, the base. Maybe trye fully writing parseInt(value,10)
Otherwise, post your code snippet? Might just be some sort of easy mistake you need a second pair of eyes on
-
January 5, 2017 at 9:23 am #1343
peterbellHmmm I tried adding the second parameter but had no luck – it still returned no value.
here is my code with the bits I have been trying to work out whats going on – including parseInt() and Number(). It also includes some logs which I will show below.
Code:
var surveyRecord = scriptContext.newRecord;
var expDenom = 0;
var understdProject = surveyRecord.getValue(‘custrecord_cs15_understood_project’);
log.debug(‘understdProject – field value’, understdProject + ‘, ‘+ understdProject.length +’ characters’)
if (understdProject > 0){
expDenom++;
}
var goodKnowledge = Number(surveyRecord.getValue(‘custrecord_cs15_good_knowledge’));
log.debug(‘goodKnowledge – number’, goodKnowledge)
if (goodKnowledge > 0){
expDenom++;
}
var easyBusiness = parseInt(surveyRecord.getValue(‘custrecord_cs15_easy_to_do_business’),10);
log.debug(‘easyBusiness – parseInt’, easyBusiness)
if (easyBusiness > 0){
expDenom++;
}
log.debug(‘expDenom’, expDenom)
if (expDenom >0)
{
var experienceAverage = twoDP((understdProject + goodKnowledge + easyBusiness)/expDenom);
surveyRecord.setValue(‘custrecord_cs15_exp_average’,experienceAverage);
}
and twoDP is just a simple functionCode:
function twoDP(number)
{
return Math.round(number*100)/100;
}
The logs show this:11072291 View Debug expDenom 5/1/2017 4:05 PM -System- 0
11072290 View Debug easyBusiness – parseInt 5/1/2017 4:05 PM -System-
11072289 View Debug goodKnowledge – number 5/1/2017 4:05 PM -System-
11072288 View Debug understdProject – field value 5/1/2017 4:05 PM -System- 9, 2 characters
Any ideas?
erictgrubaugh replied on 01/05/2017, 12:48 PM: What values are you expecting for each of these fields on this particular record?
-
January 5, 2017 at 11:29 am #1344
Olivier Gagnon NCWhat the heck… Can you add logging to output value before parseInt as well?
Shot in the dark – try parseFloat() instead??
I’ve never seen parseInt blank out a value. At worst it should return NaN.
peterbell replied on 01/06/2017, 05:38 AM: hmmm parseFloat didn’t work either – however, on editing the record rather than creation it works fine… trouble is, we want it to work on create!
-
January 5, 2017 at 7:16 pm #1345
borncorpIt’s probably some weird extra invisible character there as its saying there are two characters for the value of 9. Try doing:
Code:
parseInt(value.trim());
peterbell replied on 01/06/2017, 05:44 AM: sadly no luck here either…!
-
January 6, 2017 at 10:56 am #1346
Olivier Gagnon NCpeterbell hmmm parseFloat didn’t work either – however, on editing the record rather than creation it works fine… trouble is, we want it to work on create!
Hmmm… what are you running this on, After Submit?
Try loading the record and then read the values, rather than going with newRecord. Strongly suspect this isn’t a parseInt() thing, but a Netsuite thing…
peterbell replied on 01/10/2017, 02:13 AM: Hi Olivier – I have had a breakthrough with this! It turns out that if you load the record then grab and set the values, it works perfectly fine.
Thank you for your help
Peter
-
January 9, 2017 at 6:01 pm #1347
darrenhillconsultingHello all,
I battled with this as well. Seems like a bug. I resolved the issue by converting my field type to decimal. Not ideal, but …
-
AuthorPosts
You must be logged in to reply to this topic.