- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 06:57 AM - edited 05-26-2024 07:11 AM
HI Team,
I have written Before insert/update BR.Below are the details:
u_authority_role --> Its a list collector
My requirement is if current value in list collector is not PA even though existing/previous value can be PA, it should not push the values to array --> authorityrole.push(gr1.name);
The system is getting stuck , its only when I deactivate this it works.
Kindly help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 07:26 AM
Sorry, but your code is smelling (read https://www.opsera.io/blog/what-is-code-smell) and you really should start learning how to write code in a way that is readable and understandable!
I absolutely have no idea what you want to achieve, but at least I can tell you why your code is getting stuck. It's due to your bad index variable names in the two for loops.
I guess you wanted to write j++ and not i++ in the second loop:
for (var i = 0; i < cuauthrole.length; i++) {
for (var j = 0; j < pauthrole.length; j++) {

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 07:31 AM
@Community Alums The first issue I noticed with your script is with the second for loop where you are doing i++ instead it should be j++
var cuauth_role = current.u_authority_role.toString();
var cuauthrole = cuauth_role.split(',');
gs.info('Current aut role:' + cuauthrole);
var pauth_role = previous.u_authority_role.toString();
var pauthrole = pauth_role.split(',');
gs.info('Previous aut role:' + pauthrole);
for (var i = 0; i < cuauthrole.length; i++) {
for (var j = 0; j < pauthrole.length; j++) { //updated to j++
// gs.info('I am in loop');
if (cuauthrole[i] != pauthrole[j] && (pa.indexOf(cuauthrole[i])==-1)) {
gs.info('change found');
var gr1 = new GlideRecord('sn_customerservice_responsibility_def');
gr1.get(cuauthrole[i]);
authorityrole.push(gr1.name);
}
Also, since you didn't post the complete script, I am not sure if pa variable used at the following line is already defined in the script or not.
if (cuauthrole[i] != pauthrole[j] && (pa.indexOf(cuauthrole[i])==-1)) {
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 07:26 AM
Sorry, but your code is smelling (read https://www.opsera.io/blog/what-is-code-smell) and you really should start learning how to write code in a way that is readable and understandable!
I absolutely have no idea what you want to achieve, but at least I can tell you why your code is getting stuck. It's due to your bad index variable names in the two for loops.
I guess you wanted to write j++ and not i++ in the second loop:
for (var i = 0; i < cuauthrole.length; i++) {
for (var j = 0; j < pauthrole.length; j++) {

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 07:31 AM
@Community Alums The first issue I noticed with your script is with the second for loop where you are doing i++ instead it should be j++
var cuauth_role = current.u_authority_role.toString();
var cuauthrole = cuauth_role.split(',');
gs.info('Current aut role:' + cuauthrole);
var pauth_role = previous.u_authority_role.toString();
var pauthrole = pauth_role.split(',');
gs.info('Previous aut role:' + pauthrole);
for (var i = 0; i < cuauthrole.length; i++) {
for (var j = 0; j < pauthrole.length; j++) { //updated to j++
// gs.info('I am in loop');
if (cuauthrole[i] != pauthrole[j] && (pa.indexOf(cuauthrole[i])==-1)) {
gs.info('change found');
var gr1 = new GlideRecord('sn_customerservice_responsibility_def');
gr1.get(cuauthrole[i]);
authorityrole.push(gr1.name);
}
Also, since you didn't post the complete script, I am not sure if pa variable used at the following line is already defined in the script or not.
if (cuauthrole[i] != pauthrole[j] && (pa.indexOf(cuauthrole[i])==-1)) {
Hope this helps.