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

Community Alums
Not applicable

Yeah...it's a bit weird issue you have there... I am sure support will ask you not to use calculated value but either function field, BR or something I cant recall atm.

 

Amit Verma
Kilo Patron
Kilo Patron

Hi @joaopalmeida 

 

Just to be clear with the requirement, you want "requester_name" to be same as caller_id as and when their is a change of value in the caller_id field.

 

If yes, have you explored On-Change Client Script on caller_id field to set requester_name ?

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Hi Amit, thanks for the reply. Yes, that is what I want to happen. I have tried, but the same happened. It worked on the form as expected, but it didn't work for the list view.

Hi @joaopalmeida 

 

I just tested it using On-Change Client script and it is working both on list view and form view. Can you please check if your client script is as below. Also, please have a look on the screenshots.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
   var caller = g_form.getValue('caller_id');
   g_form.setValue('opened_by',caller);
   g_form.save();
}

 

AmitVerma_0-1705401648167.png

 

AmitVerma_1-1705401678171.png

 

AmitVerma_2-1705401716354.png

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Yes, my code was like that and yet I still tried with yours, just in case. Still doesn't work. When I create a new record, all information is fine. The problem are just the changes. It gets delayed. My form contains certain info and the list still has the information that was on the form before.

 

joaopalmeida_0-1705409345842.png

 

joaopalmeida_1-1705409350810.png

 

Plus, opened by is being populated in the same form. Our second field, is a task field, extended to incidents and ritms, I'm not sure if that affects that code.