Set a Default Purchase Order Custom Form Based on a Subsidiary

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

}

}
  1. Create a Custom Record
    1. Navigate to Customization Lists, Records & Fields > Record Types > New
    2. Name: Enter Preferred Name
    3. Include Name Field: Remove Checkmark
    4. Click Save
  2. Create a Custom Field on the Custom Record
    1. Navigate to Customization Lists, Records & Fields > Record Types
    2. Click the Custom Record created on Step 1
    3. Click New Field
    4. Label: Enter Preferred Name
    5. Type: Select Free-Form Text
    6. Store Value: Enter Checkmark
    7. Click Save
  3. Create a JavaScript File
  4. Note: Modify the IDs used on above code based on the created records on Step 1 and 2
  5. Create a Client Script Record and deploy it on the Purchase Order
    1. Navigate to Customization Scripting Scripts New
    2. Script File: Select the JavaScript File created on Step 3
    3. Click Create Script Record
    4. Click Client
    5. Name: Enter Name
    6. Click Scripts
    7. Page Init Function: Enter pageInit
    8. Field Changed Function: Enter fieldChanged
    9. Click Save & Deploy
    10. Applies To: Select Purchase Order
    11. Deployed: Enter Checkmark
    12. Status: Select Testing
    13. Click Save

Leave a comment

Your email address will not be published. Required fields are marked *