This topic contains 10 replies, has 0 voices, and was last updated by jalarson1 8 years, 6 months ago.
-
AuthorPosts
-
April 20, 2016 at 3:34 pm #23710
jalarson1I'm trying to populate a custom field in the address entry form with the value from a custom field in the customer entry form. I've been using an existing script to experiment with this. For some reason I can populate the native fields with information from the customer entry form but I am unable to do the same with a customer field. In this example I just used the companyName again to try and populate my custom address field with something, even though this is not the data I want to populate this field with.
fieldChanged_Company = function () {
//
// If the company changes, we need to update the address
//
lnSeq = nlapiFindLineItemValue('addressbook', 'defaultbilling', 'T');
if (lnSeq > 0) {
nlapiSelectLineItem('addressbook', lnSeq);
companyName = nlapiGetFieldValue('companyname');
nlapiSetCurrentLineItemValue('addressbook', 'addressee', companyName, true, true);
nlapiSetCurrentLineItemValue('addressbook', 'custom_addr_field', companyName, true, true);
console.log('companyName' + ', ' + companyName);
}
nlapiCommitLineItem('addressbook');
};
This is a cached copy. Click here to see the original post. -
April 20, 2016 at 5:51 pm #23711
girieshgjalarson1 maybe the custom field ID is incorrect? To my knowledge, IDs for Other Custom Fields start with "custrecord"… If that's not the issue, we can look elsewhere in the code for the problem.
-
April 21, 2016 at 3:41 pm #23712
jalarson1Thanks for the reply. Sorry, this is my first forum post. I meant for that to be an example. Here is the code I'm currently working with:
function fieldChanged_form(type, name) {
if (name == 'custentity_bsi_agycampus') {
var lnSeq = nlapiFindLineItemValue('addressbook', 'defaultbilling', 'T');
if (lnSeq > 0) {
nlapiSelectLineItem('addressbook', lnSeq);
var agency_campus = nlapiGetFieldText('custentity_bsi_agycampus');
nlapiSetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd', agency_campus, true, true);
}
nlapiCommitLineItem('addressbook');
}
}
If I change 'custrecord_bsi_agy_div_bur_sd' to 'addr1' the text from the 'custentity_bsi_agycampus' field gets copied over to the address 1 field in the address form the second time I change the field. I'm not sure why it only does it the second time but I'm guessing it's something simple I can figure out later. I can't figure out why I can't access my custom field in the address form.
-
April 21, 2016 at 6:07 pm #23713
k_duncHi jalarson1, just a quick thought: are your two custom fields of the same data type – e.g., Free-Form Text?
-
April 22, 2016 at 8:34 am #23714
jalarson1k_dunc No, they aren't! custentity_bsi_agycampus is a list. That's probably the problem. Thanks!
-
April 22, 2016 at 9:20 am #23715
jalarson1k_dunc, Why can't I get the text from my list field and bring it over to a free form text field? Eventually I need to take values from 3 lists, concatenate them and put them in the custom field that I added to the address form. I was thinking I could just get the text from these list fields on the customer form, put them together and put them in the custom free form text field in the address form. Is that going to be a problem?
-
April 22, 2016 at 9:29 am #23716
jalarson1k_dunc I tried changing the custom fields to be the same type, tried both nlapiGetFieldText and nlapiGetFieldValue to get the value from custentity_bsi_agycampus, still no luck getting that data to populate in the custom address field.
-
April 24, 2016 at 10:54 pm #23717
k_duncHi jalarson1, so I'm clear, custentity_bsi_agycampus is a custom list in the Customer record right? And in your Client Script, you're checking if this field's value has changed, and if so, you want to take its 'text value' and copy it to a custom address field. Am I on the right track?
If so, then certainly to read custentity_bsi_agycampus you'll need to use the nlapiGetFieldText API. Just to check, have you done an
Code:
alert(nlapiGetFieldText(custentity_bsi_agycampus + ', ' + agency_campus);
and if so, does it yield the value you're after?Okay, so next you want to locate the default billing address line – right? Now just to check, you're custom address field is an Other Custom Field with a 'Record Type' = Address. Is this correct?
To find the default billing address you can use nlapiFindLineItemValue('addressbook', 'defaultbilling', 'T'); as you've done or you could loop through all address lines until you find the one. Have you done another alert just to make sure the correct line number has been returned (don't forget that Sublists begin at 1, not 0)? Next, you use nlapiSelectLineItem as you've done. Finally, you should then use a nlapiSetCurrentLineItemValue API to set the field; which based on your code snippet above, you have done.
I'd also suggest to throw another alert in there after the nlapiCommitLineItem just to see what value has been set.
Let us know how you go.
Cheers,
Kirk.
-
April 25, 2016 at 12:13 pm #23718
jalarson1k_dunc custentity_bsi_agycampus is indeed a custom list field applied to customer and you are on the right track with all of your other questions. I am having no trouble getting the right line in the addressbook or getting the value from the custom list field. The problem seems to only be when trying to set the custom field in that line of the addressbook. So here's what I've done so far:
function fieldChanged_form(type, name) {
if (name == 'custentity_bsi_agycampus') {
var lnSeq = nlapiFindLineItemValue('addressbook', 'defaultbilling', 'T');
if (lnSeq > 0) {
console.log("selected line " + lnSeq);
nlapiSelectLineItem('addressbook', lnSeq);
var agency_campus = nlapiGetFieldText('custentity_bsi_agycampus');
nlapiSetCurrentLineItemValue('addressbook', 'addr1', agency_campus,
true, true);
console.log('agency' + ',' + agency_campus);
}
nlapiCommitLineItem('addressbook');
console.log('after commit: '
+ nlapiGetCurrentLineItemValue('addressbook', 'addr1'));
}
}
Instead of using the custom field in the addressbook I am just setting the 'Address 1' line with the text from the custom list field in the customer form. It works fine. The log looks like this:
selected line 1
agency,Agriculture, Trade and Consumer Protection, Department of
after commit: Agriculture, Trade and Consumer Protection, Department of
Now if I try this:
function fieldChanged_form(type, name) {
if (name == 'custentity_bsi_agycampus') {
var lnSeq = nlapiFindLineItemValue('addressbook', 'defaultbilling', 'T');
if (lnSeq > 0) {
console.log("selected line " + lnSeq);
nlapiSelectLineItem('addressbook', lnSeq);
var agency_campus = nlapiGetFieldText('custentity_bsi_agycampus');
nlapiSetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd', agency_campus, true, true);
console.log('agency' + ',' + agency_campus);
}
nlapiCommitLineItem('addressbook');
console.log('after commit: '
+ nlapiGetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd'));
}
}
First of all, my Eclipse NetSuite plugin which I synced to every ID I could in my account, is showing that custrecord_bsi_agy_div_bur_sd is not a valid internal id.
Second, the log looks like this:
selected line 1
agency,Agriculture, Trade and Consumer Protection, Department of
after commit: null
Thanks for the help!
-
April 25, 2016 at 3:07 pm #23719
k_duncOh dear. I can't identify any issue at all with your code. My suggestion would be to log it as a defect with NetSuite and see what they can do. I must admit though, it is of some concern that Eclipse is not picking this up as a valid field. I too quite often sync with my client accounts and very rarely get such an error, so maybe there is something to this that needs to be looked into further??? Just BTW, Store Value is checked on your custrecord_bsi_agy_div_bur_sd field?
-
April 25, 2016 at 3:13 pm #23720
jalarson1Yup, store value is checked on the custrecord_bsi_agy_div_bur_sd field. Thanks for the help. I'll take this up with NetSuite.
-
AuthorPosts
You must be logged in to reply to this topic.