-2

I have a complex ServiceNow platform - it is relatively heavily customised with Client side scripts. These scripts control customised dropdowns etc to validate data.

I now want to introduce some API connectivity. But to do this I need to introduce Server Side validation. Is there an easy way to copy validation rules from client to server side without having to develop the server side?

Timber
  • 1

2 Answers2

2

There's not a great way to "convert" client side to server side in ServiceNow. I believe you are going to have to use a script include for this.

Recommendation

If you are pulling API data into a drop down, it may cause issues with usability and may be better to store the data in the instance rather than fetch it every time someone wants to change a value. I recommend doing this so that if the API server goes down, users don't have issues in SNow, also acts as redundancy for both security & speed.

Async GlideAjax path

It is possible to use GlideAjax to call a server side script include that would do the validation & API calls.

For that you would want to use asynchronous GlideAjax, especially if it works along side APIs

var ga = new GlideAjax('some_script_include');
ga.addParam('sysparm_name', 'SomeFunction');
ga.addParm('sysparm_someparm','someValue');
ga.getXMLWait(ParseResponse);
 
function ParseResponse(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  return answer;
}

Limitations: getXMLWait() apparently doesn't work in scoped application (per SNow Community: https://community.servicenow.com/community?id=community_question&sys_id=088032badbd057042e247a9e0f96192a which also helped inform this answer)

UnisonDev
  • 21
  • 3
0

There is no easy way to do this.

Nevertheless, if you could separate UI references and data validation in the scripts, it should reduce the work as server-side javascript would also be similar. If there is a specific use case or if you can attach sample validation scripts we could guide better.

Sunil B N
  • 4,159
  • 1
  • 31
  • 52