1
votes

I don't normally use JS objects but was testing this chrome plugin (export as script) where you can basically generate script code from a search. I am having issues though with the syntax.

function GetEmployee()
{
	var columns = [];
	var employeeSearch = nlapiSearchRecord('employee'[['access', 'is', 'T'], "AND", ["internalid", "anyof", "121212"]], [columns[0] = new nlobjSearchColumn('internalid'), ]);
	if(employeeSearch)
	{
		for (var i = 0; employeeSearch != null && i < employeeSearch.length; i++)
		{
			var record = nlapiLoadRecord('employee', employeeSearch[0].getValue(columns[0]));
			var id = record.getId();
			nlapiLogExecution('DEBUG', 'return id', id)
		}
	}
	return true;
}

Error: That search or mass update does not exist. My saved search returns a record so I was expecting the code to do the same...

1

1 Answers

2
votes

Your nlapiSearchRecord parameters are not correct. You forgot a comma after 'employee' and second paramenter is the searchid not search filters.

var employeeSearch = nlapiSearchRecord('employee', null, [['access', 'is', 'T'], "AND", ["internalid", "anyof", "121212"]], [new nlobjSearchColumn('internalid') ]);

Also, you already have the internalid of the employee, why do you want to use a search?

And, you always get 'internalid', you don't need to add a column again for that.

var employeeSearch = nlapiSearchRecord('employee', [['access', 'is', 'T'], "AND", ["internalid", "anyof", "121212"]]);
if(employeeSearch.length){
     for(var i = 0; i < employeeSearch.length; ++i){
        nlapiLogExecution('AUDIT', 'id', employeeSearch[i].id);
     }
 }

You can directly use nlobjSearchResult.id