Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Service Portal Catalog Client Script Issue

doernbrackc
Kilo Expert

Screen Shot 2016-12-29 at 10.25.30 AM.png

What we are trying to do is hide the u_internal_external field from external users. This script seems to work but the problem is that users who are internal are not seeing the field. Initially I though there was code error. The ! implies that user who does not have the snc_external role then hide the field. I removed the ! because doing so implies that the user who has the external role should not see the field. When doing this and testing with an internal user the internal user sees the field. However, a user with the snc_external role is also seeing the field. What is the problem?

1 ACCEPTED SOLUTION

Our developer seems to have figured this out. Looks like a GlideAjax script is needed. To be honest I don't really follow the script so if anyone would like to attempt to explain it I would appreciate it.



function onLoad() {


  //Type appropriate comment here, and begin script below


  var aj = new GlideAjax('GetInternalExternalCSM');


  aj.addParam('sysparm_name','getExternal1');


  aj.getXMLAnswer(fun);



  //Type appropriate comment here, and begin script below




  function fun(answer)


  {


  var obj = JSON.parse(answer);


  if(obj.internal == true)


  {


  g_form.setReadOnly('u_internal_external',false);


  g_form.setMandatory('u_internal_external',true);


  }


  else if(obj.external == true)


  {


  g_form.setVisible('u_internal_external',false);


  }}




  }


View solution in original post

21 REPLIES 21

drjohnchun
Tera Guru

Can you replace the whole IF statement with this and try:



g_form.setDisplay('u_internal_external', !g_user.hasRole('snc_external'));



Hope this helps.



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

Winner of November 2016 Members' Choice Award


I tried that but the external user still sees the field.


Screen Shot 2016-12-29 at 10.46.45 AM.png


Can you then try



g_form.setDisplay('u_internal_external', !g_user.hasRoleExactly('snc_external'));



You may also try confirming the roles first by adding this before the setDisplay() line above:



alert(g_user.hasRole('snc_external'));


alert(g_user.hasRoleExactly('snc_external'));


Abhinay Erra
Giga Sage

Use else and set the display to true. Add this to the code



else{


g_form.setDisplay('variable name', true);


}