how to use record.type as script parameter
# ask-stanley-ai
t
how to use record.type as script parameter
c
AI generated answer (using internal Slack threads):
To use
record.type
as a script parameter in SuiteScript, you can access it from the record object that is passed into your script context. This can be useful when you want the same script to behave slightly differently depending on the type of record that triggered it. Here's an example of how you might use
record.type
in a script:
Copy code
javascript
function afterSubmit(context) {
    var record = context.newRecord;
    var recordType = record.type;

    if (recordType === 'salesorder') {
        // Do something for sales orders
    } else if (recordType === 'purchaseorder') {
        // Do something for purchase orders
    }
}
In this example, the
afterSubmit
function is triggered after a record is submitted. The
context.newRecord
object contains the new state of the record that was just submitted. The
record.type
property gives you the type of the record. If you want to set a script parameter with code rather than the UI, you can use the
record.submitFields
method. However, this is undocumented and may break at any time. Here's an example:
Copy code
javascript
record.submitFields({
    id: deploymentInternalId,
    type: record.Type.SCRIPT_DEPLOYMENT,
    values: {
        "custscript_interco_je_last_run_date": format.format({type: format.Type.DATETIME, value: runDate.toDate()}),
    },
})
In this example, the
record.submitFields
method is used to set a script parameter (
custscript_interco_je_last_run_date
) to the last run date of the script. Alternatively, you could use custom records or the
runtime.getCurrentSession
method to store and retrieve dynamic parameters for your script. ****** 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.82169193
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.816499472
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.813743412
Please provide your feedback on this answer.