Reference field has different value from the one showing on list

joaopalmeida
Tera Contributor

Hello everyone! I need some help with this issue.

 

So we have a field in the Task table (let's consider requester_name) and on Incidents I have the regular caller_id. We need to have that requester_name, because our client asked for it. When I change the caller_id in a form, I want requester_name to have the same value, and it does, even if we check the xml it is correct. But when I go back to the list, the value displayed in that column, instead of being the new one is the value it had before the update. And it goes on, like this: 

 

                                On Form | On List

When created:             A              A

When updated first:    B             A

3rd update:                    C            B

and so on....

 

Here is the example of the form:

joaopalmeida_0-1705337829636.png

And here are the values on the list:

 

joaopalmeida_1-1705337888734.png

 

And finally, this is the function we have on the Calculated field:

 

(function calculatedFieldValue(current) {

    // Add your code here

    if(current.sys_class_name  ==  'incident'){
       
        return current.ref_incident.caller_id.toString();
           
   
    }
    else if(current.sys_class_name  ==  'sc_req_item'){
   
        return current.ref_sc_req_item.requested_for.toString();
       
    // return the calculated value
   
    }
})(current);
 
All help is appreciated, thanks in advance! 🙂
1 ACCEPTED SOLUTION

Dr Atul G- LNG
Tera Patron
Tera Patron

HI @joaopalmeida 

Log a Now Support case. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

View solution in original post

12 REPLIES 12

Ehab Pilloor
Mega Sage

Hi @joaopalmeida,

The behavior you're describing, where the calculated field displays the correct value on the form but not in the list after an update, might be related to how the list is configured or the timing of when the calculation occurs.

Ensure that the list layout includes the updated `requester_name` field and that it is correctly mapped to the calculated field. Sometimes, the list layout might not reflect changes immediately.

Additionally, the calculated field script you've provided seems straightforward, and it correctly fetches the `caller_id` or `requested_for` based on the `sys_class_name`. However, to troubleshoot the list display issue, consider adding a business rule or script to recalculate the field or refresh the list after an update to see if that resolves the discrepancy.

Moreover, check if there are any client-side scripts or UI policies that might interfere with the list display. Debugging tools in the browser console can help identify any errors or unexpected behavior in the client-side scripts.

Review the order of execution for business rules, client scripts, and calculated fields can provide insights into when the calculation occurs in the update process. Adjustments to the timing or sequencing of these elements might resolve the issue.

Ensure the list layout is configured correctly, consider triggering a recalculation or list refresh in response to updates, and review client-side scripts or UI policies that might impact the field display on the list.

 

If you found this reply useful, please mark it as solution/helpful.

 

Thanks and Regards,

Ehab Pilloor

Hi, thanks for you reply! I've done those things, we have no UI policies nor scripts except this one I just showed there, that is on the field itself. I've tried debugging it but it is taking me nowhere, because on the form is aways correct and on the list is always different.

Community Alums
Not applicable

calculated value is triggered on displayng/get the record. With list it wont work as expected as it creates the value of that field "virtually" - its not real data saved in the DB but created on the fly when using the record itself.

Yet theres a trick that worked for me few times.

Dont use if/else but ternary expression.

Something like :

return current.sys_class_name == "incident" ? current.ref_incident.caller_id +"" :  current.ref_ sc_req_item.requested_for + "";

Joro, thanks for your reply. I've tried you advice, but it still doesn't work. The behaviour is the exact same, having our piece of code or yours, but I could understand how the list works based on your explanation and I appreciate that!