Make topic visible IF user is a Manager or HR

Yasmin
Kilo Guru

Hello, I'm trying to display a topic on the topic list ONLY if the user is a manager OR if the user if from Human Resources. 

I have a javascript code that I've been using on other topics inside the conversation flow to go thru different conversation paths in the topic depending on the user (manager /HR or non-HR) and it works when the code is inside the conversation flow. But if try to use the same code placing it on the Script condition (properties tab) of the topic, nothing happens. Wondering if anyone has done something similar that has worked.

Thank you.

find_real_file.png

var manager_and_HR = new sn_hr_core.hr_Criteria().evaluateById("a8df765e1bca3300167b759d1e4bcbdd", gs.getUserID());

    var isManager = vaInputs.search_user.u_ismanager;

 

    if (isManager)

       return true;

    if (manager_and_HR)

       return true;

    if (!isManager && !manager_and_HR)

       return false;

 

1 ACCEPTED SOLUTION

Susan Britt
Mega Sage
Mega Sage

Hi Yasmin,

Yes, try this.

find_real_file.png

View solution in original post

4 REPLIES 4

Susan Britt
Mega Sage
Mega Sage

Hi Yasmin,

Yes, try this.

find_real_file.png

Thank you sbritt! It's working nicely

Chris D
Kilo Sage
Kilo Sage

See how sbritt's solution works for you - seems good to me.

To add something else, your code is using a vaInputs variable in it - I'm pretty confident vaInput variables aren't even initialized before the topic is started but even if they were, they'd still have no values when the topic availability is being checked. That seems to be your issue.

Thank you for catching that Chris. I ended up removing that line from the script. Sbritt's script is working perfectly. 

Had a developer look into it and came up with a simplified version

{
var manager_and_HR = new sn_hr_core.hr_Criteria().evaluateById("a8df765e1bca3300167b759d1e4bcbdd", gs.getUserID());
gs.info('YM - manager_and_HR = ' + manager_and_HR);
if (manager_and_HR)
       return true;
}

Both scripts (scbritt's and this one) are working good.

Thank you all!