Knowledge

harry24
Tera Contributor

Hello , 

 

How to write script in user criteria so that if their is an article in German language then the knowledge author and owner of that article can view the article irrespective of whatever is their language?

if (userGR.preferred_language == 'de'|| current.u_owner == gs.getUserID() || current.author==gs.getUserID()) {
return true;
}

 

this script is partially working 

Thanks 

 

23 REPLIES 23

harry24
Tera Contributor

For example , KB105607 is in German Language .

Abel's preferred language is German, so she is able to view KB105607.

Although Ankur is the owner of KB105607 he is not able to view it as his preferred language is English , so it allow this I have written below script,

var userGR = new GlideRecord('sys_user');
userGR.get(user_id);
if (userGR.preferred_language == 'de'|| current.u_owner == gs.getUserID() || current.author==gs.getUserID()) {
return true;
}
return false;

@harry24 

update as this

var userGR = new GlideRecord('sys_user');
userGR.get(user_id);
if (userGR.preferred_language.toString() == 'de') {
    answer = true;
} else if (current.u_owner == user_id || current.author == user_id) {
    answer = true;
} else
    answer = false;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

still not working 

@harry24 

Did you debug and add logs?

please share your debugging analysis

are you sure the field name u_owner is correct?

var userGR = new GlideRecord('sys_user');
userGR.get(user_id);
if (userGR.preferred_language.toString() == 'de') {
    answer = true;
} else if (current.u_owner == user_id || current.author == user_id) {
    gs.info('Inside owner or author found');
    answer = true;
} else
    answer = false;
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes the field names are correct and also used debugging but else if is not getting executed