- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 01:50 PM
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
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- 11,231 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 02:15 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2017 07:44 AM
Can you share the script and some details of the requirement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2017 04:29 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2017 05:48 PM
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:
- Create a read ACL for (your table name).comments
- Add the condition "Catalog Item is not (your high security cat_item)"
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2017 05:56 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2017 06:25 PM
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)"
-Brian