RE: 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
*/

 

define([‘N/record’],
/**
* @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’);
log.debug(‘EmployeeId’,empcode);
log.debug(‘SuperVisorName’,SupervisorName);
log.debug(‘SuperVisorId’,SuperVisorId);

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

});
phoneCall.setValue(‘title’, ‘Call HR for benifits’);
phoneCall.setValue(‘assigned’,employee.entityid);
phoneCall.save();
}

}
};

});

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

Pradeep Rookie Asked on September 9, 2020 in SuiteScript.
Add Comment
2 Answers

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.