0
votes

I am an inexperience technical developer working on my first SuiteScript using SuiteScript 1.0. I am getting an SSS_MISSING_REQD_ARGUMENT error, but I am sure there are many more in my code. The purpose of the script is to populate the department field on the expense record line item from a joined record. The end user will select a Project on the expense line, and the script should look up the department on the project record (a custom field) and add the value to the native department field. Code is copied below.

function ProjectSegment ()
{
    var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());

    var recordID = nlapiGetRecordId(record);

    //internal ID of project record
    var project = nlapiGetField ('custcol_nra_expense_project');

    //load project record
    var precord = nlapiLoadRecord('job', project);

    //get department on project record (internal ID)
    var pdepartment = precord.GetFieldValue('custentity_nra_dept_project');

    //get project name from project record
    var projectName = precord.GetFieldText('entityid');

    //load existing search
    var search = nlapiLoadSearch('job','customsearch161');

    //add filter to include project name
    search.addFilter(new nlobjSearchFilter('entityid',null,'is',projectName));

    //run search
    var resultSet = search.runSearch();

    //get department line
    var departmentResult = new nlobjSearchColumn('custentity_nra_dept_project');

    //set value
    nlapiSetFieldTexts('job','department',1,departmentResult)

    //record.commitLineItem('department');
    nlapiSubmitRecord(record, true);
}
2

2 Answers

1
votes

//internal ID of project record var project = nlapiGetFieldValue ('custcol_nra_expense_project');

0
votes

Praveen Kumar's response is correct regarding the missing required argument, but there are many other issues with the script as you've surmised.

Side notes:

  • The getFieldValue and getFieldText methods of nlobjRecord are not capitalized.
  • For performance reasons, you could/should use a search to get the values you need from the job record. Loading a record just to get field values is wasteful unless you mean to change the record.
  • Your search filter should probably be based on the value (not text) of the entityid in the job record.
  • Your desired search column probably is invalid (I don't think a custentity field could be on a job record).
  • Getting the search result is incorrect.

You want something like this instead:

var result = resultSet.getResults(0, 1);
if (result) {
    var department = result.getValue('custentity_nra_dept_project');
    // etc.
}

All that said, though, from your description, I don't think you need the search anyway. Once you have pdepartment (again, using precord.getFieldValue), I think all you need is:

record.setFieldValue('department', pdepartment);

Or if you're setting the line-level department, it would be different.

What kind of script is this? I'd like to make more recommendations, but it depends on what's going on.