Set a default Purchase Order Custom Form to be used based on a Subsidiary. This is achievable by creating a Custom Record that has a Custom Field which will contain the Subsidiary information and set the Custom Form on a Purchase Order using a Client Script.
function fieldChanged(type,name)
{
//Get the subsidiary selected in 'subsidiary' field
var sub = nlapiGetFieldValue('subsidiary');
//and store sub in custom record field for future reference
if(name=='subsidiary' || name=='customform'){
var r = nlapiLoadRecord('customrecord_base_record','1');
//'customrecord_base_record' is a record type id of custom record
//'1' is an internal id of custom record created in step 4
r.setFieldValue('custrecord2',sub);
//'custrecord2' is an internal id of custom subsidiary field in custom record
nlapiSubmitRecord(r);
}
if(name=='subsidiary'){
if(sub=='3')
nlapiSetFieldValue('customform','78');
else if(sub == '5')
nlapiSetFieldValue('customform','108');
//Similarly, add more conditions if you have to set the custom form based on subsidiary
}
}
function pageInit(type)
{
//Read the subsidiary stored in custom record and set that to 'subsidiary' field
if(type == 'create'){
var r = nlapiLoadRecord('customrecord_base_record','1');
var sub = r.getFieldValue('custrecord2');
nlapiSetFieldValue('subsidiary',sub,false);
//Set firefieldchanged = false, so that it again doesn't trigger fieldChanged function
}
}
- Create a Custom Record
- Navigate to Customization > Lists, Records & Fields > Record Types > New
- Name: Enter Preferred Name
- Include Name Field: Remove Checkmark
- Click Save
- Create a Custom Field on the Custom Record
- Navigate to Customization > Lists, Records & Fields > Record Types
- Click the Custom Record created on Step 1
- Click New Field
- Label: Enter Preferred Name
- Type: Select Free-Form Text
- Store Value: Enter Checkmark
- Click Save
- Create a JavaScript File
- Note: Modify the IDs used on above code based on the created records on Step 1 and 2
- Create a Client Script Record and deploy it on the Purchase Order
- Navigate to Customization > Scripting > Scripts > New
- Script File: Select the JavaScript File created on Step 3
- Click Create Script Record
- Click Client
- Name: Enter Name
- Click Scripts
- Page Init Function: Enter pageInit
- Field Changed Function: Enter fieldChanged
- Click Save & Deploy
- Applies To: Select Purchase Order
- Deployed: Enter Checkmark
- Status: Select Testing
- Click Save