I am trying to create a custom record everytime a ...
# suitescript
k
I am trying to create a custom record everytime a transaction record is created, edited or copied. does the following code validate it? I am concerened about the COPY event type:
Copy code
if(scriptContext.type == scriptContext.UserEventType.EDIT || scriptContext.type == scriptContext.UserEventType.XEDIT || scriptContext.type == scriptContext.type == scriptContext.UserEventType.CREATE || scriptContext.type == scriptContext.type == scriptContext.UserEventType.COPY){
            
            var customRecordId = createCustomRecord();
            log.debug('Custom Integration Record Id', customRecordId);
}
n
you have a mistake in your code.
Copy code
|| scriptContext.type == scriptContext.type == scriptContext.UserEventType.CREATE || scriptContext.type == scriptContext.type == scriptContext.UserEventType.COPY
you've probably doubled up when you pasted...
should be:
Copy code
|| scriptContext.type == scriptContext.UserEventType.CREATE || scriptContext.type == scriptContext.UserEventType.COPY
k
so COPY is a valid, userEventType arguement though?
e
Copy is only valid in
beforeLoad
Also a more concise way to express this condition:
Copy code
if ([
  scriptContext.UserEventType.COPY,
  scriptContext.UserEventType.CREATE,
  scriptContext.UserEventType.EDIT,
  scriptContext.UserEventType.XEDIT
].indexOf(scriptContext.type) > -1) {
k
what does this do
indexOf(scriptContext.type) > -1
? and is there something similar for COPT in
afterSubmit
?
e
No, every
copy
event becomes a
create
during the submit events
👍 1
j
indexOf can be used to check if an array contains the specified element. Kinda like in_array() in PHP. If it returns -1 the element is not in the array. More info here: https://www.w3schools.com/jsref/jsref_indexof.asp
👍 1
k
thank you @erictgrubaugh and @jen