- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 09:16 AM
Hi Everyone,
I have a table Declaration goods Table which has two fields Commodity code and Commodity code hierarchy. Commodity code is referencing custom table which has commodity code, Goods Desc and Hierarchy Desc.
My requirement is to print commodity code hierarchy field with Hierarchy Desc value only if Goods Desc is Other.
I have written a Before BR for this which has below code
Please let me know where im wrong
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 10:01 AM
Hi @Divya Kandula ,
I tried your problem in my PDI and it works for me, can you please use below code
var comHierarchy = current.u_commodity_code_hierarchy;
var gr = new GlideRecord('sn_customerservice_commodity_code'); //custom table
gr.addEncodedQuery('sys_id=' + current.u_commodity_code);
gr.query();
if (gr.next()) {
var goodsDesc = gr.u_hierarchy_description;
comHierarchy = goodsDesc.replace(/[||]+/g, '\n');
}
current.setValue('u_commodity_code_hierarchy', comHierarchy);
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 10:01 AM
Hi @Divya Kandula ,
I tried your problem in my PDI and it works for me, can you please use below code
var comHierarchy = current.u_commodity_code_hierarchy;
var gr = new GlideRecord('sn_customerservice_commodity_code'); //custom table
gr.addEncodedQuery('sys_id=' + current.u_commodity_code);
gr.query();
if (gr.next()) {
var goodsDesc = gr.u_hierarchy_description;
comHierarchy = goodsDesc.replace(/[||]+/g, '\n');
}
current.setValue('u_commodity_code_hierarchy', comHierarchy);
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 10:27 AM
Thank you @Community Alums i dont know how i missed this line

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 10:32 AM
Hi,
A few pointers.
Avoid using current.update in a business rule, because you risk ending up with an infinite loop. (the update causes an update, which causes an update and so on).
In this particular scenario I think there is no need to query the other table for the value, because if you have a valid reference to the record, you can dot-walk to get the attribute directly instead.
Providing a simple example on how you can do below, just replace the fields to ones that suit your requirements.
var someValue = current.u_custom_attribute_reference.u_some_field_value.toString();
var updatedDescription = '';
if (someValue){
updatedDescription = someValue.replace('text_to_replace', 'replacement_text');
}
if (updatedDescription){
current.setValue('some_other_field_to_update_on_current_record', updatedDescription);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 10:42 AM
I tried dot walking but it dint work for some reason