Check,ing if current user is the Assigned to user

KamakshiM
Tera Contributor

 

I have written a simple Business Rule on the Incident table to practice on my PDI:

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    let assignedTo= current.assigned_to;
    let currentUser = gs.getUser().getID();
    if (assignedTo ==  currentUser){
         current.subcategory = 'antivirus';
    }

})(current, previous);
 
The condition (assignedTo ==  currentUser) is evaluating to false even though the two variables have the exact same value when I log them.
I have tried: ===, trim, localeCompare, assignedTo.getValue() == gs.getUser().getID() and a few other things. But it evaluates to false every time.
How could this be?
3 REPLIES 3

Animesh Das2
Mega Sage

hi @KamakshiM ,

Please try this.

    var assignedTo= current.getValue('assigned_to');
    var currentUser = gs.getUserID();
    if (assignedTo ==  currentUser){
         current.subcategory = 'antivirus';
    }
 

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

Hi Animesh,

  Thanks for your response. 

That did not work because getUniqueValue() returns the primary key and it is a different value.

But your suggestion prompted me to try getValue() and that worked!!

Hi @KamakshiM ,

 

Correct, geUniqueValue() does not take any arguments and it gives the sys_id of the current record here. In this case getValue() is the best option. Glad that it worked for you I also edited my response later.

 

If my response address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das