Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Can I use extended operators with a conditions field?

jordanwalsh
Mega Contributor

I've implemented a conditions field on one of my tables, and I'm trying to evaluate another table that meets the criteria set up in the conditions field:

  gs.info("Querying " + scenario.reference_table + " for " + current.sys_id);

  gs.info("Quering using criteria: " + scenario.criteria);

  var entity = new GlideRecord(scenario.reference_table);

  entity.addQuery("sys_id",current.sys_id);

  entity.addEncodedQuery(scenario.criteria);

  entity.query();

This is currently returning a criteria that looks like:

Quering using criteria: priority=1^EQ

and this is working as expected.   however when I add the extended_operators attribute to my conditions field, then the criteria evaluation returns an error.

extended_operators=VALCHANGES;CHANGESFROM;CHANGESTO

I then update the criteria to use a 'CHANGESTO' and the following log is generated:

Quering using criteria: priorityCHANGESTO1^EQ

The following error is generated on the UI:

Syntax Error or Access Rule Violation detected by database (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHANGESTO 1' at line 1)

5 REPLIES 5

Not applicable

Hi Jordan,



You can not use "changes", "changes from" in your custom GlideRecord object. These are the functions of GlideElement class and available at the time of transaction/operation only.


Like we can use these functions in business rule.



Thanks,


Param


Thanks Param.



So my use case is to allow a user to save a predefined action when a specific criteria has been met on a record.



My users are currently asking for the ability to say when field x changes to value y, execute the action.



At this stage I am saving the criteria within an object, then when anything that extends from the Task table changes, I check the criteria against the record that has changed.   If the change matches the criteria, I fire off the predefined action.



Can you recommend a different way that would achieve what I am trying to accomplish?



thanks



Jordan


Hi Jordan,



I do not think you can use Extended Operators like ChangesTo in Encoded-queries or Glide Object. I will say make some entries like Field Name , OLD Value , New Value and then use it in your glide-record logic.  



Thanks,


Rajeev Lochan



PS: Hit like, Helpful or Correct depending on the impact of the response


Not applicable

Hi Jordan,


I didn't get you exactly, but might be below line help you :



Best way to achieve this by business rule. Just apply the business rule on parent table. You can also use condition like current.sys_class_name=='child_table' to run this business rule in case of your specific table only.



Thanks,


Param