suitescript to set customform when copy record
# ask-stanley-ai
k
suitescript to set customform when copy record
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that you are trying to set a custom form when copying a record using SuiteScript. In a User Event (UE) script, you can't use
N/currentRecord
as it's not available in a server-side script. Instead, you can use
context.newRecord.id
to get the record ID. However, it seems that NetSuite doesn't allow you to use
record.load
or
record.setValue
to change the form within a UE script, and it won't throw an error if you try to do so. One solution that was mentioned is to use
record.submitFields
in the UE script. Here's a sample code snippet:
Copy code
javascript
var recordId = record.submitFields({
    type: record.Type.INVOICE,
    id: context.newRecord.id,
    values: {
        customform: yourCustomFormId
    },
    options: {
        enableSourcing: false,
        ignoreMandatoryFields : true
    }
});
In a Client Script (CS), you can use
N/currentRecord
to get the current record. You can set the custom form in the
pageInit
function when the record type is 'create'. Here's a sample code snippet:
Copy code
javascript
function pageInit(context){
  let rec = context.newRecord;
  if(context.type==='create'){
    rec.setValue({
      fieldId: 'customform',
      value: 88,
      ignoreFieldChange: false
    });
  }
}
Please replace
88
with your custom form ID. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.838195801
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.83380127
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.833313
Please provide your feedback on this answer.