- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2015 01:09 PM
What I am envisioning is a background script which creates a specific gliderecord, then tests the query for it, then deletes it so you can run that automatically every time you want to test with very little user input?
So I would really appreciate if someone could help me with the script. Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2015 10:51 PM
It will be good to further see what type of conditions you want to test; but yes, it does makes sense... in most part .
The piece which has me puzzled is why will you like to test a filter against a record and then delete the record? Once you delete it, it's gone! If you run the script again, it will test 0 records.
If you're trying to build a unit testing framework, there are some "still basic" tools out there that can help you with this task. The following links could be of help:
Unit Test Utility - Test Driven Development as we move closer to PaaS
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2015 01:16 PM
So basically I am looking to build a script to test filter conditions in ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2015 01:27 PM
Hello, it sounds interesting what you mention but I don't quite understand what you're trying to accomplish. Would you mind elaborating?
Based on what i understand so far, perhaps the following will help...
// User only touches this section -----------------
var table_name = 'incident'; // change the table to test the filter on
var query = 'active=true'; // add the encoded query that you will like to test here
var field_to_display = 'number'; // add the name of the field to display
// End of User Edit Section ----------------------------
var gr = new GlideRecord (table_name);
gr.addEncodedQuery(query);
gr.query();
gs.print('There are ' + gr.getRowCount() + ' records');
while (gr.next()){
gs.print ('This is the value of ' + field_to_display + ' : ' + gr[field_to_display]);
}
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2015 02:01 PM
Hi Berny,
So, I have a method which has filter conditions in it within a script include. So, basically I want to write a background script to check those conditions in my method and make sure the conditions still work.
For example: There may be a lot of errors in the below code. But just to give you the idea on what I am trying to accomplish here.
var gr = new GlideRecord("alm_hardware");
gr.favorite_food = "cookie";
gr.othervalue = "something";
gr.insert();
var evaluator = new PNCTransformUtils();
var testResult = evaluator.myFunctionThatChecksConditions(gr,"Arrow");
if(testResult = true) { gs.log("allGood")}
else {gs.log("fail")}
gr.delete();
Hope this makes sense to you?
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2015 09:31 PM
Hi Mohammed,
I have responded to a similar posting from yourself here:
I had not read this post when I responded.
Just so you know.
Best Regards
Tony