- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 01:34 AM
Solved! Go to Solution.
- 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();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 03:27 AM
Try this, you will certainly need to make some modifications but here is a basic framework and I have added comments to show where sys_id is fund and where it is not found
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(',');
for (var c = 0;c< pasa.length;c++)
{
if (authrole.toString().indexOf(''+pasa[c]) > 0) {
//sys_id found
//do whatever
}
else
{
//sysId not found
gr.u_comments = "" + "Responsiblity for account " + current.company.name + " and contact " + current.contact.name + " has changed to:" + authorityrole.toString();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 03:48 AM
@Anurag Tripathi I am getting below error now:
java.sql.BatchUpdateException: (conn=2399162) Duplicate entry 'bob@coastal.com' for key 'user_name'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 04:05 AM
Where are you updating anything?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 01:57 AM
Hi @Community Alums ,
You are splitting with comma & then checking the index Of. Rather first iterate over the arrays using for loop to & then check indexof inside the loop.
for (var j = 0; j < pasa.length; j++)
{
if (authrole.indexOf(pasa[j]) !== -1)
{
I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 03:09 AM
auth_role -->Has comma separated sys_ids
pasa -->Has comma Separated sys_ids
My requirement is to find any sys_id of pasa is in auth_role. If no ids found then goto For loop and add comments else do not go.