Server Script If Statements

yundlu316
Kilo Guru

Hi Experts, I'm trying to code a widget in Service Portal that serves up the correct Knowledge Article based on a person's role and location.   There's an added layer of complexity when either the Role or Location or even both do not match.   In those cases, I would like them to be served up with a default article.   Here are some of the scenarios:

find_real_file.png

                                                                   

RolesLocationKnowledge Articles
AnalystWashington, DCKB 100
AnalystNew York, NYKB 200
AnalystSan Francisco, CAKB 300
Washington, DCKB 400
AnalystKB 500

KB 100 - 300 are pretty self explanatory.   If those combinations are the same as the User, then they get served with those articles.   However, if a User is an Analyst but not in any of those three cities, I would like them to be served with KB 500.   If a User is in DC but is not an Analyst, I want them to be served with KB 400.   Finally, if the User is not an Analyst and not in one of those three cities, I want them to be served with KB 600.  

I have a beginner's understanding of angular js, so getting the Knowledge Article values for the first three cases I think looks like this:

var hr = new GlideRecord('my_hr_cases');

hr.addQuery('hr_profile', gs.getUserID());

var ka = new GlideRecord('my_knowledge');

if(hr.hr_profile.user.location == ka.location && hr.position.role == ka.role)

{

data.article = ka.knowledge_article.getHTMLValue();

}

else if()

I'm stuck in how to expand on this so the other scenarios would provide the correct Knowledge Article values.   My end step is to dynamically set URL based on these combinations with HTML:

<a id="KA_link" href="/kb_view.do?sysparm_article={{data.article}}" target="_blank">The Right Article</a>

Any help is greatly appreciated.

Thanks!

10 REPLIES 10

Hi Goran and joemccarty, yea unfortunately I'm on Helsinki.   Will bring this up to the group though, that's a pretty awesome upgrade.   Thanks!