Hi experts trying to create a phone call using suite scripts.

I tried crewating a phone call at the time of creating a new employee – an excercise .

* @NApiVersion 2.0
* @NScriptType UserEventScript


* @param {record} record
function(record) {

return {
afterSubmit: function(context){
//log.debug(‘Hello World’);
var employee = context.newRecord;

var empcode = employee.getValue(‘custentity_employee_code’);
var SuperVisorId = employee.getValue(‘supervisor’);
var SupervisorName = employee.getText(‘supervisor’);

if(context.type == context.UserEventType.CREATE){
var phoneCall = record.create({
type : record.type.PHONE_CALL,

phoneCall.setValue(‘title’, ‘Call HR for benifits’);



but Im getting this error.

{“type”:”error.SuiteScriptError”,”name”:”SSS_INVALID_API_USAGE”,”message”:”Invalid API usage. You must use getValue to return the value set with setValue. “,”stack”:[“anonymous(N/serverRecordService)”,”<anonymous>(/SuiteScripts/SuiteScript2/Sdr_ue_employee.js:21)”],”cause”:{“type”:”internal error”,”code”:”SSS_INVALID_API_USAGE”,”details”:”Invalid API usage. You must use getValue to return the value set with setValue. “,”userEvent”:”aftersubmit”,”stackTrace”:[“anonymous(N/serverRecordService)”,”<anonymous>(/SuiteScripts/SuiteScript2/Sdr_ue_employee.js:21)”],”notifyOff”:false},”id”:””,”notifyOff”:false,”userFacing”:false}

please provide a solution thanks

Rookie Asked on September 9, 2020 in SuiteScript.
Add Comment
2 Answer(s)

There are 2 ways of setting a field, using setValue and setText. if you set a field using setValue, you can only get its value using getValue. If you set a field using setText, then you can only get its text using setText. The supervisor field was set using setValue, so you can only get the internal id value of the supervisor using getValue.

Workaround is to use search.lookupFields (or use the slower record.load) to get your data instead

Advanced Answered on September 9, 2020.
Add Comment

Took me a really long time to figure this one out, even with the explanation.

As battk said, the problem is var SupervisorName = employee.getText(‘supervisor’); and it only occurs when you are creating a new employee record. The code (at least through the part that sets those variables) works fine if you submit an existing employee record.

My theory (complete newbie, so beware) is that because it’s a new record, the association needed to go straight to the getText() doesn’t exist  yet. That’s why it works fine on existing records. But the supervisor ID works fine because you set that during the employee creation (or it’s null). The hop over to the value associated with that ID can’t be made yet, at least not with getText().

Still way too new to suggest how to fix that as battk did. But since that line of code is irrelevant to the exercise (which is about the phone task), you should just comment that out.

(And it’s been almost 2 years since you posted this so you’ve certainly moved on, but if anyone else equally stumped ends up here in this same context, that’s the solution.)

Rookie Answered on June 3, 2022.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor