This topic contains 8 replies, has 0 voices, and was last updated by egrubaugh 8 years, 6 months ago.
-
AuthorPosts
-
May 13, 2016 at 1:02 pm #2021
jalarson1I have a custom field in the address form that I am populating on a user event script, before submit function that is attached to sales order on create. My script is working to populate the custom address field in the customer record but this data does not show up in the billing address on the sales order. For some reason when a sales order is entered in the web store by the customer, the billing address defaults to ‘custom’ instead of choosing the default billing address for the customer. It is still the right billing address, just shows up as ‘custom’ in the drop down instead of the label associated with the default billing address.
When I click the button next to the billing address drop down on the sales order to open up the address form associated with that address, the data is filled in on my custom address field. It just is not showing up in the address block because the ‘Override’ checkbox also defaults to ‘True’. When I uncheck the ‘Override’ checkbox, the custom address field data pops up in the address block and displays exactly as I want it to.
I tried to set the ‘Override’ checkbox to ‘F’ in my script but it isn’t working. I think it’s because the checkbox is checked in the address subrecord associated with ‘Custom’. I don’t understand how the ‘Custom’ option in the drop down field works. The test customer I was using had the billing address filled in before filling out the purchase order so I have no idea why ‘Custom’ keeps showing up as the billing address instead when making a purchase in the web store. Can somebody shed some light on this for me?
This is a cached copy. Click here to see the original post. -
May 16, 2016 at 11:13 am #2022
jalarson1I think my script is causing the sales order to default to ‘custom’ instead of the default billing address. Do I need to commit the changes to the billing address subrecord on the customer record as well as commit it to the sales order? Right now I am committing the address subrecord and the customer record but the sales order must be using the billing address as it was before I updated it and thus defaulting to ‘custom’.
-
May 16, 2016 at 12:03 pm #2023
egrubaughCan you provide more of your actual code? Would help to see what’s going on,
-
May 16, 2016 at 12:19 pm #2024
jalarson1Code:
function userEventBeforeSubmit(type) {
if (type == ‘create’) {
var agencyValue = ”;
var divisionValue = ”;
var bureauValue = ”;var agencyAbbrev = ”;
var divisionAbbrev = ”;
var bureauAbbrev = ”;var agy_div_bur_short_desc = ”;
var customerId = nlapiGetFieldValue(‘entity’);
// load the customer record using the internal id acquired above
var customerRec = nlapiLoadRecord(‘customer’, customerId, {
recordmode : ‘dynamic’
});var billingAddr = customerRec.findLineItemValue(‘addressbook’,
‘defaultbilling’, ‘T’);if (billingAddr > 0) {
customerRec.selectLineItem(‘addressbook’, billingAddr);
var addrSubrec = customerRec.editCurrentLineItemSubrecord(
‘addressbook’, ‘addressbookaddress’);var customField = addrSubrec
.getFieldValue(‘custrecord_bsi_agy_div_bur_sdesc’);if (customField == ”) {
agencyValue = customerRec
.getFieldText(‘custentity_bsi_agycampus’);// if agency field is not empty, get the text from the division
// field
// otherwise, end the process and send an alert
if (agencyValue != ”) {divisionValue = customerRec
.getFieldText(‘custentity_bsi_divdept’);
// if the division field is not empty, get the text from the
// bureau
// field
// otherwise, end the process and send an alert
if (divisionValue != ”) {bureauValue = customerRec
.getFieldText(‘custentity_bsi_bureausect’);agencyAbbrev = searchAgyDivBurRecords(agencyValue,
‘customrecord_bsi_agycampus’);if (agencyAbbrev != ”) {
divisionAbbrev = searchAgyDivBurRecords(
divisionValue, ‘customrecord_bsi_divdept’);if (divisionAbbrev != ”) {
agy_div_bur_short_desc += agencyAbbrev + ‘-‘
+ divisionAbbrev;if (bureauValue != ”) {
bureauAbbrev = searchAgyDivBurRecords(
bureauValue,
‘customrecord_bsi_bureausect’);if (bureauAbbrev != ”) {
agy_div_bur_short_desc += ‘-‘
+ bureauAbbrev;
}
}
}
}} else {
alert(‘The customer is missing a value for the required Division/Department field.’);
// SHUT IT DOWN!
}} else {
alert(‘The customer is missing a value for the required Agency/Campus field.’);
// SHUT IT DOWN!
}if (agy_div_bur_short_desc != ”) {
addrSubrec.setFieldValue(
‘custrecord_bsi_agy_div_bur_sdesc’,
agy_div_bur_short_desc);addrSubrec.commit();
customerRec.commitLineItem(‘addressbook’);var x = nlapiSubmitRecord(customerRec);
} else {
alert(‘Unable to find data for EMPLOYER SHORT DESCRIPTION on the customer address form.’);
}
}
} else {
// shut it down
alert(‘A default billing address was not found on the customer record.’);
}
}
}function searchAgyDivBurRecords(sValue, sRecord) {
var searchValue = sValue;
var searchRecord = sRecord;var abbrevSubrec = ”;
var filter = new Array();
filter[0] = new nlobjSearchFilter(‘name’, null, ‘is’, searchValue);function getSubrecId(currentRecord) {
var abbrevSubrecs = {
‘customrecord_bsi_agycampus’ : ‘custrecord_bsi_agycampus_shortdesc’,
‘customrecord_bsi_divdept’ : ‘custrecord_bsi_divdept_shortdesc’,
‘customrecord_bsi_bureausect’ : ‘custrecord_bsi_bureausect_shortdesc’
};
return abbrevSubrecs[currentRecord];
}abbrevSubrec = getSubrecId(searchRecord);
var columns = new Array();
columns[0] = new nlobjSearchColumn(‘name’);
columns[1] = new nlobjSearchColumn(abbrevSubrec);var searchResults = nlapiSearchRecord(searchRecord, null, filter, columns);
if (searchResults.length == 1) {
return searchResults[0].getValue(abbrevSubrec);
} else {
return ”;
}
} -
May 16, 2016 at 12:25 pm #2025
jalarson1When my script is not deployed, the billing address will default to the default billing address. When this script is deployed, the billing address on the sales order will default to ‘custom’. I want to make sure that if the customer chose their default billing address that is the billing address that is on the sales order. However, if they choose a custom billing address I want that address to show up on the sales order but still have the custom address field populated based on this script.
-
May 16, 2016 at 12:53 pm #2026
egrubaughJust FYI, alerts will not work server-side, so there’s no need to add them in your user event script; better to log that information.
Also it would be helpful to use CODE tags and maintain indentation in your code sample.
-
May 16, 2016 at 1:03 pm #2027
jalarson1Ok, thanks. Sorry about the messy code. I think I need to set the billing address on my sales order as well as on the customer record. Can I just set the field ‘billaddress’ and add my custom data to the second line? I’m not sure how ‘billaddress’ is put together with line breaks and everything but can I just get the data from the ‘billaddress’ field, parse it out, add in my custom data and set the field?
-
May 17, 2016 at 1:41 pm #2028
jalarson1egrubaugh I figured it out. Thanks for the tips.
-
May 17, 2016 at 2:03 pm #2029
egrubaughNot sure I helped too much Glad you figured it out.
-
AuthorPosts
You must be logged in to reply to this topic.