- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 10:54 AM
Quick scripting question as I'm not entirely experienced with my while loops. This a before insert/update BR:
(function executeRule(current, previous /*null when async*/) {
var person = current.u_person;
var mgr = person;
while(mgr.manager != 'af7ef72a89488500e4382dea5d5a1cee'){
mgr = mgr.manager;
}
current.u_manager = mgr;
current.u_division_director = mgr.manager;
})(current, previous);
Basically my while script is waiting for the Manager to be a specific person. This works awesome. and is filling u_manager with the right person every time. What I want is for it to wait for the Manager to either be one person OR the other. So I tried changing my while too look like
while(mgr.manager != 'af7ef72a89488500e4382dea5d5a1cee' || mgr.manager != '8a8d381d8915c900e4382dea5d5a1cc0'){
....
And...
while(mgr.manager != 'af7ef72a89488500e4382dea5d5a1cee' || '8a8d381d8915c900e4382dea5d5a1cc0'){
....
And...
while(mgr.manager != ('af7ef72a89488500e4382dea5d5a1cee' || '8a8d381d8915c900e4382dea5d5a1cc0')){
....
Is it not possible to do this? Am i just getting the format wrong? Should one of those have worked and I just typed it incorrectly?
These just make the page keep spinning...
Thanks in advance for your help!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 11:10 AM
That's a good idea, and actually the one I started with, but in this case i found I need to do a while loop so it keeps going until it find the right sys_id to push into the right field.
Alas, I figured it out, I should have used the AND condition. Not the OR condition.
Thanks for taking a look at this!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 11:08 AM
Hi Alex,
you can use if condition instead of while loop.
- if(mgr.manager != 'af7ef72a89488500e4382dea5d5a1cee' || mgr.manager != '8a8d381d8915c900e4382dea5d5a1cc0'){
- ....
Are you looking to get the manager of the Person?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 11:10 AM
That's a good idea, and actually the one I started with, but in this case i found I need to do a while loop so it keeps going until it find the right sys_id to push into the right field.
Alas, I figured it out, I should have used the AND condition. Not the OR condition.
Thanks for taking a look at this!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 11:10 AM
Your first one is the best one Alex. You are looking for A || B to be true where A is manager != sysID1 and B is manager != sysID2
Try this instead... since mgr.manager is an object and may not compare equality to a literal string... get the sysID by itself first.
Since I don't see any looping type of objects (e.g. an array, an IF might be better here.
var mgrSysID = mgr.getValue('manager');
if (mgrSysID != 'af7ef72a89488500e4382dea5d5a1cee' || mgrSysID != '8a8d381d8915c900e4382dea5d5a1cc0') {
mgr = mgr.person;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 11:13 AM
You need to use AND (&&) in that scenario.
With the OR operator you will never exit that loop. If manager DOES equal 'af7ef72a89488500e4382dea5d5a1cee' then your next condition (mgr.manager != '8a8d381d8915c900e4382dea5d5a1cc0') will always evaluate to true.