Need to set u_unit_price based on u_requirement_type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi everyone,
I need help populating the unit price field based on the requirement type.
Here’s what I’m working with:
I have a field called u_requirement_type (which contains equipment like eg.. Dell Latitude, iPhone 14,...)that takes references another table which is " Equipment Catalog" .
I want u_cost_per_item to automatically populate based on the selected u_requirement_type, pulling the corresponding price from that same referenced table which is " Equipment Catalog".
What I’ve tried so far:
I attempted to set u_cost_per_item as a reference to the same table that u_requirement_type points to.
I also looked into changing the display option from false to true, but I understand that the display option on the " Equipment Catalog" table can only be applied to one column which I’ve already used for u_requirement_type.
Could someone guide me on how to correctly set this up so that the unit price auto-fills based on the selected requirement type?
Thanks in advance for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @bharathrdyd ,
To auto-populate the u_cost_per_item field based on the selected u_requirement_type, you don't need to make u_cost_per_item a reference field. Instead, you can use a client-side script (like a UI Policy or Client Script) to fetch the price from the referenced Equipment Catalog record and set it dynamically.
Solution:-
- Field Configuration
- u_requirement_type: Reference field to Equipment Catalog table.
- u_cost_per_item: Decimal or Currency field (not a reference).
- Client Script (Type: onChange)
Create an onChange Client Script on the u_requirement_type field:
(function executeRule(current, gForm, gUser, gSNC) {
// Get the selected Equipment Catalog record
var equipment = gForm.getReference('u_requirement_type', function(ref) {
if (ref && ref.u_price) {
gForm.setValue('u_cost_per_item', ref.u_price);
} else {
gForm.setValue('u_cost_per_item', '');
}
});
})(current, gForm, gUser, gSNC);
Note:- This script uses getReference() to fetch the full record from the Equipment Catalog and sets the u_cost_per_item field using the u_price field from that record.
Alternative: Business Rule (Server-side)
If you prefer server-side logic (e.g., for catalog items or workflows), you can use a Business Rule (on insert/update):
(function executeRule(current, previous /*null when async*/) {
if (current.u_requirement_type) {
var equipment = new GlideRecord('equipment_catalog'); // Replace with actual table name
if (equipment.get(current.u_requirement_type)) {
current.u_cost_per_item = equipment.u_price;
}
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Best,
Anupam.
