How can I add revenue line items where the Product Type is set to Item by default using Groovy?
You can write a Groovy script in Application Composer to insert in the Before Insert and Update Insert triggers of the Opportunity Revenue object. Here's a sample of the code that you can change to suit your requirements.
define([
'vb/action/actionChain',
'vb/action/actions',
'vb/action/actionUtils',
], (
ActionChain,
Actions,
ActionUtils
) => {
'use strict';
class opportunitiesChildRevenueOnCreateEventListener extends ActionChain {
/**
* @param {Object} context
* @param {Object} params
* @param {{row:object,child:object[],related:object[],deDuplicateConfig:object}} params.previous
* @param {{row:object,parentRow:object,mode:string}} params.event
* @return {{row:object,child:object[],related:object[],deDuplicateConfig:object}}
*/
async run(context, { previous, event }) {
const { $layout, $base, $extension, $responsive, $user, $constants, $variables } = context;
// Set default value for ProductType when creating a new revenue line
let row = JSON.parse(JSON.stringify(previous?.row));
if (event?.mode !== 'create') {
return;
}
row.ProductType = 'Item';
previous = {};
previous.row = row;
return previous;
}
}
return opportunitiesChildRevenueOnCreateEventListener;
});