Written my first script - with some help from Goog...
# suitescript
p
Written my first script - with some help from Google...but as expected...it is not quit right! It should • copy the Campaign fields and create a new custom record each time a new Campaign is created. • Only when the Campaign Type id = 10 1. It creates a new custom record one when it is edited too 2. It create a new custom record regardless of Type = 10
Copy code
define(['N/record', 'N/runtime'], function (record, runtime) {
    function copyCampaignToCustomRecord(context) {
        // Get the ID of the new campaign record
        var campaignId = context.newRecord.id;
        // Load the campaign record
        var campaignRecord = record.load({
            type: record.Type.CAMPAIGN,
            id: campaignId,
            isDynamic: true
        });
        // Check the category type of the campaign
        var category = campaignRecord.getValue({fieldId: 'category'});
        if (category === '10') {
            // Create a new custom record
            var customRecord = record.create({
                type: 'custrecord_wg_exp_campaign_name',
                isDynamic: true
            });
            // Copy values from the campaign record to the custom record
            customRecord.setValue({
                fieldId: 'custrecord_wg_exp_campaign_name',
                value: campaignRecord.getValue({fieldId: 'campaignname'})
            });
            customRecord.setValue({
                fieldId: 'custrecord_wg_start_date',
                value: campaignRecord.getValue({fieldId: 'startdate'})
            });
            customRecord.setValue({
                fieldId: 'custrecord_wg_end_date',
                value: campaignRecord.getValue({fieldId: 'enddate'})
				
            });
			customRecord.setValue({
                fieldId: 'custrecord_wg_subsidiaries',
                value: campaignRecord.getValue({fieldId: 'custevent17'})
				
            });
            // Save the custom record
            customRecord.save({
                ignoreMandatoryFields: true
            });
        }
    }
    return {
        afterSubmit: function (context) {
            if (runtime.executionContext === runtime.ContextType.USER_INTERFACE) {
                copyCampaignToCustomRecord(context);
            }
        }
    };
});
Hoping someone can point me in the right direction. Thanks!
a
1. you can add a filter to check context type if you don't want to execute in edit mode 2. check the typing of your values and research === vs ==
n
^^ 2. he's doing exact matching with the outcome it always matches and creates a record, if he'd done == "10" I'd have said that might be the issue if it wasn't creating records.