
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 01:34 AM
HI Team,
In Below script IndexOf is not working. its always getting passed and control is going beyond IF loop even I ave out condition as if (authrole.toString().indexOf(pasa) == -1) .. This means if record is not found it should go but its going even if its not found. I want to stop this/
var authorityrole = [];
var gr = new GlideRecord('customer_contact');
gr.addQuery('sys_id', current.contact);
gr.query();
while (gr.next()) {
var pa = gs.getProperty('sn_customerservice.PASA');
var pasa = pa.split(',');
gs.info('PASA:' + pasa);
if (current.u_authority_role.changes()) {
var auth_role = current.u_authority_role.toString();
gs.info('AuthRole:' + auth_role);
var authrole = auth_role.split(',');
if (authrole.toString().indexOf(pasa) == -1) {
gs.info('insideIF');
for (var i = 0; i < authrole.length; i++) {
gs.info('Into Res:');
// gs.info('Got PASA:');
authorityrole.push(authrole[i]);
}
gr.u_comments = "" + "Responsiblity for account " + current.company.name + " and contact " + current.contact.name + " has changed to:" + authorityrole.toString();
}
}
Solved! Go to Solution.
1 ACCEPTED SOLUTION

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 04:42 AM
This is the complete code.
var authorityrole = [];
var gr = new GlideRecord('customer_contact');
gr.addQuery('sys_id', current.contact);
gr.query();
while (gr.next()) {
var pa = gs.getProperty('sn_customerservice.PASA');
var pasa = pa.split(',');
gs.info('PASA: ' + pasa);
if (current.u_authority_role.changes()) {
var auth_role = current.u_authority_role.toString();
gs.info('AuthRole: ' + auth_role);
var authrole = auth_role.split(',');
var found = false;
for (var i = 0; i < pasa.length; i++) {
if (authrole.indexOf(pasa[i]) !== -1) {
found = true;
authorityrole.push(pasa[i]);
}
}
if (found) {
gs.info('insideIF');
gr.u_comments = "Responsibility for account " + current.company.name + " and contact " + current.contact.name + " has changed to: " + authorityrole.toString();
}
}
}
10 REPLIES 10

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 04:42 AM
This is the complete code.
var authorityrole = [];
var gr = new GlideRecord('customer_contact');
gr.addQuery('sys_id', current.contact);
gr.query();
while (gr.next()) {
var pa = gs.getProperty('sn_customerservice.PASA');
var pasa = pa.split(',');
gs.info('PASA: ' + pasa);
if (current.u_authority_role.changes()) {
var auth_role = current.u_authority_role.toString();
gs.info('AuthRole: ' + auth_role);
var authrole = auth_role.split(',');
var found = false;
for (var i = 0; i < pasa.length; i++) {
if (authrole.indexOf(pasa[i]) !== -1) {
found = true;
authorityrole.push(pasa[i]);
}
}
if (found) {
gs.info('insideIF');
gr.u_comments = "Responsibility for account " + current.company.name + " and contact " + current.contact.name + " has changed to: " + authorityrole.toString();
}
}
}