comparison between two strings

Maharshi Chatte
Kilo Guru

Hi,

I have two variables - test and target .both contains a list of sys_Id separated by comma. Now I have to write a business rule which compare the sys_ids in test with that of the target and will throw an error message if any of the sys_id in test is not present in the target. How can I write a script for this?

 

 

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Maharshi,

Fields "test" and "target" are both of type "list".

  var testArray = test.split(',');
  var targetArray = target.split(',');

  var arrayUtil = new ArrayUtil();

  var intersect = arrayUtil.intersect(targetArray, testArray);

  if (intersect.length != testArray.length) {
     gs.addErrorMessage('There are some items in test array that is not in target array.');
     current.setAbortAction(true);

 I've tested the script using the following code to make sure it works as expected.

var target = '4f1764429780111086d3b4b3f153afba,4f1764429780111086d3b4b3f153afbd,4f1764429780111086d3b4b3f153afbc,62826bf03710200044e0bfc8bcbe5df1,a8f98bb0eb32010045e1a5115206fe3a'
var grTable = new GlideRecord('a0_table2');
if (grTable.get('4f1764429780111086d3b4b3f153afbc')) {
  var test= grTable.u_list_field;  // field of type 'list'
  
  var testArray = test.split(',');
  var targetArray = target.split(',');

  var arrayUtil = new ArrayUtil();

  var intersect = arrayUtil.intersect(targetArray, testArray);

  if (intersect.length != testArray.length) {
     gs.addErrorMessage('There are some items in test array that is not in target array.');
     current.setAbortAction(true);
  }
}

View solution in original post

19 REPLIES 19

Jaspal Singh
Mega Patron
Mega Patron

Since, these are variables you need a check before submission or after submission?

Hi,

I want to prevent them from submitting the record if there is any value in test variable that do not match with the values in target.

What is the variable type of variables. Text, Reference, List collector, etc.?

The variables are list type