how to query in a related list ?

revathy
Kilo Expert

Hi All,

I have created a related list in a customer table (eg:coco-cola) called "Subscriptions" that is referring to a "subscription table". I need to get the users name who subscribed to that particular record(coco-cola). The only condition to query is "display name contains the customer name (coco-cola)" how do i write the query condition in my related list script.???

Script which i wrote:

-------------------------

(function refineQuery(current, parent) {

                     

                      current.addQuery('subscription', parent.profile );

 

})(current, parent);

This script is fetching all the values from the table. So how do i write the query condition to get the records in which the "display name contains my customer name"(u_customer_name)??

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Revathy,



Refer below links which would be helpful to you:


http://wiki.servicenow.com/index.php?title=Creating_Defined_Related_Lists#gsc.tab=0



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I found this particular line from the wiki article useful:


  • When scripting your condition, current is the record to which you want to add queries while parent is the main record being displayed.


I was having the same issue and had to switch the variable names.   Then the Query worked properly.


Boom.  This, right here.  Your comment saved me a lot of time in debugging.  I was using current.field instead of parent.field until I read your comment.  

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Revathy,



Any update on this?


Can you mark answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps people to find similar question easily. Thanks in advance.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader