On a Purchase Order, in an After Submit script, I ...
# ask-stanley-ai
s
On a Purchase Order, in an After Submit script, I load a related case record and update a field with the transaction number. I am only getting "To Be Generated" as the transaction number. How do I get the PO# instead to fill in that field?
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** The issue you're experiencing is due to the fact that the transaction number (tranid) is not generated until after the record is saved. When your After Submit script runs, the transaction number is still in the "To Be Generated" state. To get the actual Purchase Order number, you can use a User Event script with the After Submit event. In this script, you can load the Purchase Order record and get the transaction number (tranid) which should now be generated. Here is a sample script:
Copy code
javascript
function afterSubmit(scriptContext) {
    if (scriptContext.type !== scriptContext.UserEventType.CREATE)
        return;

    var newRecord = scriptContext.newRecord;
    var poNumber = newRecord.getValue('tranid');

    // Load the related Case record and update the field
    var caseRecord = record.load({
        type: record.Type.CASE,
        id: 'YOUR_CASE_RECORD_ID'
    });

    caseRecord.setValue('customfield', poNumber);
    caseRecord.save();
}
Please replace 'YOUR_CASE_RECORD_ID' and 'customfield' with your actual Case record ID and the custom field ID you want to update. Remember to deploy the script and associate it with the Purchase Order record type.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.852783203
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.842041075
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.841125488
Please provide your feedback on this answer.