related list not showing for particular user

questsal78
Giga Expert

Hi,

In tasks form view, I've related list of "Assets" for a particular user(Relationship). If there is an "asset item" then related list of "Assets" will show all assets assigned to that user, if there is no user assigned to that asset then whoever is "requested for" then it will list all the assets belong to that user. If "asset item" is empty then it'll display all the assets for "requested for" person.

My query is working fine with all users except for "Ryun Truman", for some reason when I search for all assets of this user I don't get any results but if I apply the filter with "contains" then it does show 2 assets belong to this user. I've tried different thing but query works fine for all users in above scenario except for "Ryun Truman". I'm able to find this user in "Users" tables also.

Can you please help me where is the problem.

Asset.PNG

Related Assets.PNG

(function refineQuery(current, parent) {

  var r = parent.request;

  var rf = r.requested_for;

  var pc = parent.u_asset_item.asset_tag ;

  if (!pc.nil()){

  var res = new GlideRecord('alm_hardware');

  res.addQuery('asset_tag',pc);

  res.query();

  res.next();

  if (!res.assigned_to.nil())

  {

  current.addQuery('assigned_to','CONTAINS',res.assigned_to);

  current.addQuery('State','In use').addOrCondition('State','In Excess');

  }

  else

  {

  current.addQuery('assigned_to','CONTAINS',rf);

  current.addQuery('State','In use').addOrCondition('State','In Excess');

  }

  }

  else

{

  current.addQuery('assigned_to','CONTAINS',rf);

  current.addQuery('State','In use').addOrCondition('State','In Excess');

  }

})(current, parent);

task.PNG

Thank you,

Mujtaba Ahmed

1 ACCEPTED SOLUTION

Shaun Hillier
Kilo Guru

Hi Mujtaba



I can't see any obvious reason why this isn't working. But can give you a useful tool to debug.


At the end of your code if you add:



gs.log("Current Query:"+current.getEncodedQuery(),"Mujtaba Ahmed");



This will print out the encoded query into the logs. You can then copy this into the browser, your_instance/[your_table]_list.do?sysparm_query=[the query] to see exactly what the code is doing. Helpful to spot any errors.



Regards



Shaun


View solution in original post

2 REPLIES 2

Shaun Hillier
Kilo Guru

Hi Mujtaba



I can't see any obvious reason why this isn't working. But can give you a useful tool to debug.


At the end of your code if you add:



gs.log("Current Query:"+current.getEncodedQuery(),"Mujtaba Ahmed");



This will print out the encoded query into the logs. You can then copy this into the browser, your_instance/[your_table]_list.do?sysparm_query=[the query] to see exactly what the code is doing. Helpful to spot any errors.



Regards



Shaun


Hi Shaun,



Thank you very much for you reply. I've tried as you've mentioned above but it returns nothing and when I tried filtering and copy paste query URL from filter it does return correct assets.



Capture.PNG



https://[my-instance].service-now.com/alm_hardware_list.do?sysparam_query=assigned_toCONTAINSfab1ca0... use^ORState=In Excess



query.PNG



It's working fine with all other users so I'll continue to look into cause of this issue.



Thank you,


Mujtaba