Difference between dot-walk and getElement()

Nam Nguyen
Tera Expert

Hi folks

Is there be any difference between the following, specifically in terms of performance?

var value = current.request_item.cat_item;

var value = current.getElement('request_item.cat_item');

Thanks

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Nam,



As far as I know, there's no difference in performance. Both return a GlideElement object. That being said, based on the script you wrote, you are looking for a value and for that you would want getValue() which doesn't work on dot-walking. I haven't tried getElement() with a dot-walk notation. Have you seen it used somewhere? Test it and let me know.



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


View solution in original post

9 REPLIES 9

Can you share the script and some details of the requirement?


The requirement is to filter out comments from comments_and_worknotes for requested item from certain item category



I found that by using a restrict business rule as below on sys_journal_field would do the trick, but at the cost of serious performance degradation


(function executeRule(current, previous /*null when async*/) {


  var reqid = current.getEncodedQuery().toString().match(/element_id=\w+/g)[0].split("=")[1];


  var req = new GlideRecord("sc_req_item");


  req.get(reqid);


  if (req.getValue('cat_item')=='a7fb9a97db9172008de5f34ebf961910'){ //high security cat_item


      current.addQuery("element","!=","comments");


  }


})(current, previous);



Any clue?


Hi Nam,



I can't quite wrap my head around how you are using this, perhaps some more details would be helpful.


  • What table have you created this BR to run on?
  • Is this a concern for data being displayed on the form, in a list, both?
  • Have you considered alternative methods, such as ACLs to restrict the data?


(e.g.)


I believe the comments field is wide open OOB (no ACLs restricting access), so:



  1. Create a read ACL for (your table name).comments
  2. Add the condition "Catalog Item is not (your high security cat_item)"
  3. Save


This will filter all comments for that type of cat item from the Comments and Work Notes journal list, unless you add another ACL granting some specific role/etc. the ability to still see them.   However this will not remove the comment entries from an Activity list if you have that displayed, because that gets its data from the History tables, I believe.




Thanks,


-Brian


Nam Nguyen
Tera Expert

Hi Brian,



I have an ACL to restrict comments, however it only works for Activity filter but not Comments and Worknotes field for some reason



The BR is being put on the sys_journal_field table, it is a concern for data being displayed in both List and Form views



wwar1ace


Hi Nam,



Try placing an ACL on whatever task table you are trying to work with... e.g., if this is for catalog tasks, make it for [sc_task].



Following that example, create a read ACL for sc_task.comments where the condition is "Request_item.Item is not (your high security item)"


temp20170309.png





-Brian