- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I would like to change the "Cost Name" in Cost Plans.
I want the cost name automatically generated after pressing the Create labor costs button to display the name of the assigned employee.
I believe the name generated by the CostPlanForFinancialAttributes script is defined. How can I modify this to output the employee name as the cost name?
I want to add the employee name after the default generated name, like _XX.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
@WataruS You can have the employee name added to the cost plan name easily using the out of box logic by making the 'User' field a financial attribute.
Please check out this page to know more: https://www.servicenow.com/community/spm-articles/generate-labor-cost-plans-by-individual-resources-...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @WataruS,
The cost plan name is generated in the CostPlanForFinancialAttributes script include, specifically in the _setAttributeValuesAndCostPlanName method. Out-of-the-box it always starts with "Resource" and then concatenates attribute display values.
If you want to append the assigned employee name (e.g. Resource_Capex_Internal_Alexa Smith), the recommended approach is to leave OOTB code intact (so you don’t lose changes during upgrades) and add your own customization layer.
Option: To Extend the script include (not recommended for upgrades)
_setAttributeValuesAndCostPlanName: function(attributeValues, gr) {
let costPlanName = gs.getMessage('Resource');
// set values of attributes and unit_cost present in attributeValues object
for (const [column, obj] of Object.entries(attributeValues)) {
if (column === 'unit_cost') {
gr.setValue(column, obj);
} else {
gr.setValue(column, obj.value);
}
let name = costPlanName + "_" + obj.displayValue;
costPlanName = (obj.value && column !== 'unit_cost') ? name : costPlanName;
}
// Append employee name if available
if (attributeValues['resource'] && attributeValues['resource'].value) {
let userGr = new GlideRecord('sys_user');
if (userGr.get(attributeValues['resource'].value)) {
costPlanName += "_" + userGr.getDisplayValue();
}
}
gr.setValue('name', costPlanName);
}
Recommended Option: Use a Business Rule on cost_plan
- Create an after insert Business Rule on the cost_plan table.
- Check if it’s a labor cost plan (is_labor_cost_plan = true).
- Query the related resource_allocation > resource (sys_user).
- Update the name field to append the employee’s display name.
Why this way?
- Keeps the OOTB Script Includes upgrade-safe.
- Your logic is isolated and easy to maintain.
- You can always remove the BR if the requirement changes.
P.S. Please make sure to test this first in your PDI or a lower environment.
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi, @M Iftikhar
Thank you for answering.
First, I tried adding to the script, but it didn't work properly and the employee's name wasn't added. Is there anything else I should add here?
Considering the impact of the update, I understand that addressing it through business rules is preferable.
Could you please provide a bit more detail on how to configure the following two points?
- Query the related resource_allocation > resource (sys_user).
- Update the name field to append the employee’s display name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @WataruS,
Could you please try the below script in your business rule and see if it helps?
(function executeRule(current, previous /*null when async*/) {
if (!current.is_labor_cost_plan)
return;
// Find related allocation
var alloc = new GlideRecord('resource_allocation');
alloc.addQuery('task', current.task);
alloc.query();
if (alloc.next() && alloc.user) {
var user = new GlideRecord('sys_user');
if (user.get(alloc.user)) {
current.name = current.name + "_" + user.getDisplayValue();
current.update();
}
}
})(current, previous);
This logic checks for the related resource_allocation, pulls the associated sys_user, and appends the display name to the cost plan record’s name field.
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @M Iftikhar
Thank you for your information.
I have created the Business rule based on your information.
However, the employee's name was not added.
Are there any other items that need to be configured?