Which entry point in UserEvent is advisable to cal...
# suitescript
t
Which entry point in UserEvent is advisable to call the record.attach?
b
im guessing you mean on create, which means your only choices is after submit
theoretically you can use beforeLoad if you only need it to work in the ui, but thats really weird
t
I see.. I am also attaching record on the aftersubmit. But I encounter some issue without error message
Apparently, I am trying to attach file to 2 records consecutively. It works in sandbox but when I deploy it in production, It doesnt work
b
what does the code look like
t
function attachFileToRecord(dealRecId, cserId, fileId, version) {
log.audit({title: 'reportToAttachToRecord', details: record1: ${recordId1} record2: ${recordId2} fileId: ${fileId} version: ${version}});
getGovernance();
const fields = [];
fields['aaa'] = fileId;
fields['bbb'] = version;
utility.submitFlds(customrecord_123, recordId1, fields);
utility.attachFileToRecord(fileId, 'customrecord_first', recordId2);
utility.attachFileToRecord(fileId, 'customrecord_second', recordId1);
getGovernance();
}
///utility///
function attachFileToRecord(fileId, recordType, recordId) {
try {
record.attach({
record: {
type: 'file',
id: fileId
},
to: {
type: recordType,
id: recordId
}
});
} catch (e) {
log.debug({title: 'attachFileToRecord', details: e});
}
}
b
not enough code, recordId2 and recordId1 are not defined
customrecord_123 is not defined either, though i probably guess that
I personally would toss the submitFields related code, if you think its not related to the problem
expect to share something that i can toss into my account
t
ah got it for a moment
function attachFile(dealRecId, cserId, fileId) {
const fields = [];
fields['file_attachment_fld'] = fileId;
attachFileToRecord(fileId, cfg.CSER.RECTYPE, cserId);
attachFileToRecord(fileId, cfg.DEAL.RECTYPE, dealRecId);
}
function attachFileToRecord(fileId, recordType, recordId) {
try {
record.attach({
record: {
type: 'file',
id: fileId
},
to: {
type: recordType,
id: recordId
}
});
} catch (e) {
log.debug({title: 'attachFileToRecord', details: e});
}
}
function afterSubmit(context) {
// dealRecordId is internal id of the other custom record
// otherRecordId is internal id of the other custom record
attachFile(dealRecordId, otherRecordId, fileId);
}
so from aftersubmit we will call another function
b
Copy code
function attachFile(dealRecId, cserId, fileId) {
  attachFileToRecord(fileId, "customrecord0", cserId);
  attachFileToRecord(fileId, "customrecord1", dealRecId);
}
function attachFileToRecord(fileId, recordType, recordId) {
  try {
    record.attach({
      record: {
        type: "file",
        id: fileId,
      },
      to: {
        type: recordType,
        id: recordId,
      },
    });
  } catch (e) {
    log.debug({ title: "attachFileToRecord", details: e });
  }
}
function afterSubmit(context) {
  // dealRecordId is internal id of the other custom record
  // otherRecordId is internal id of the other custom record
  attachFile("1", "6", "3143");
}
worked for me
your code is fine
which suggests that either your custom records or file is different between sandbox and production
t
We are thinking maybe the folder permission is the cause.. I will try to update this convo so other will have reference.. Thank you @battk for checking this with me as well keanu thanks