Sunday, January 6, 2019

Attach File to a Record via CSV Import

This article will help user to create an alternate solution for attaching a file via CSV import(enhancement 220827).

Sample script

function attach(type, form){
     // declare a variable customfieldid to get the file's internal id
    currentContext = nlapiGetContext();

    if(currentContext.getExecutionContext() == 'csvimport' && type == 'edit'){ 
        nlapiAttachRecord('file', nlapiGetFieldValue(customfieldid), nlapiGetRecordType(), nlapiGetRecordId());
    
}
}

1. Create a custom body field. Customization > Lists, Records, & Fields > Entity Fields > New

  • Label: File ID
  • Type: Document
  • Store Value: checked
  • Applies To: Customer
  • Save
2. Create a new user event script. Customization > Scripting > Scripts > New > User Event.
3. Enter information needed on the Basic Information:

  • Name: (name of your script) 
  • Scripts > Script : Upload the sample script Below.
  • After Submit Function: attach
  • Deployments > Applies to: Customer
                   Deployed: Yes
                   Status: Released

  • Save
4. Update the customer record using CSV Import (Setup > Import/Export > Import CSV Records)
  • The CSV file needs at least two columns, one for customer ID and one for the file ID (the file attachment). 

 

Note: Please make sure that Run Server SuiteScript and Trigger Workflows is enabled in the CSV Import Preferences and the file is uploaded to file cabinet.

 

No comments:

Post a Comment