PlanetJupiter
02/01/2023, 1:52 PMdefine(['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!apaule
02/01/2023, 4:32 PMNElliott
02/01/2023, 4:51 PM