- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 12:37 PM
Hi everyone!
I need some help, I'm developing a UI Action that should insert a new record into the cost_plan_breakdown table.
For a Cost Plan, when I'm in one of those records,
I should be able to be inside the record, clic the UI Action and then create a new Cost Plan Break Down. Here is my code. Those are the list results. What i want is to insert the indicated record, the record that matches with the next one in the cost plan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 03:25 PM - edited 07-18-2023 04:26 PM
Hi Daniel142,
I took a stab at creating a UI action based on your description. This is what I have:
The script follows:
(function(current, previous, gs, action) {
// gs.addInfoMessage('Cost Plan = ' + current.name);
// Get desired fiscal period
var cpbFP = '';
var curDateTime = new GlideDateTime();
var fp = new GlideRecord('fiscal_period');
fp.addQuery('fiscal_type', '=', 'month');
fp.addQuery('fiscal_start_date_time', '>', curDateTime);
fp.orderByDesc('name');
fp.query();
var fpSysid = '';
// loop through results and capture the last value
while (fp.next()) {
fpSysid = fp.sys_id;
}
// gs.addInfoMessage("fiscal_period sys_id = " + fpSysid + ".");
// Now create the new record
var cpb = new GlideRecord('cost_plan_breakdown');
cpb.initialize();
cpb.cost_plan = current.sys_id;
cpb.fiscal_period = fpSysid; // from logic from posted script
// add additional field values as desired
var sysId = cpb.insert();
if (sysId)
gs.addInfoMessage("Created new cost plan breakdown");
else
gs.addInfoMessage("Failed creating new cost plan breakdown.");
// action.setReturnURL(current);
// action.setRedirectURL(cpb.getGlideRecord());
})(current, previous, gs, action);
I took from another OOB UI Action as an example, and script logic from your image (modified as I couldn't copy that). This seems to work, but can use improvement.
BTW, there is a New button on the cost_plan_breakdown related list on the cost_plan form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 03:25 PM - edited 07-18-2023 04:26 PM
Hi Daniel142,
I took a stab at creating a UI action based on your description. This is what I have:
The script follows:
(function(current, previous, gs, action) {
// gs.addInfoMessage('Cost Plan = ' + current.name);
// Get desired fiscal period
var cpbFP = '';
var curDateTime = new GlideDateTime();
var fp = new GlideRecord('fiscal_period');
fp.addQuery('fiscal_type', '=', 'month');
fp.addQuery('fiscal_start_date_time', '>', curDateTime);
fp.orderByDesc('name');
fp.query();
var fpSysid = '';
// loop through results and capture the last value
while (fp.next()) {
fpSysid = fp.sys_id;
}
// gs.addInfoMessage("fiscal_period sys_id = " + fpSysid + ".");
// Now create the new record
var cpb = new GlideRecord('cost_plan_breakdown');
cpb.initialize();
cpb.cost_plan = current.sys_id;
cpb.fiscal_period = fpSysid; // from logic from posted script
// add additional field values as desired
var sysId = cpb.insert();
if (sysId)
gs.addInfoMessage("Created new cost plan breakdown");
else
gs.addInfoMessage("Failed creating new cost plan breakdown.");
// action.setReturnURL(current);
// action.setRedirectURL(cpb.getGlideRecord());
})(current, previous, gs, action);
I took from another OOB UI Action as an example, and script logic from your image (modified as I couldn't copy that). This seems to work, but can use improvement.
BTW, there is a New button on the cost_plan_breakdown related list on the cost_plan form.