Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

User / Customer Role Membership Check in ISF / Javascript

Did not see this in the documentation...

Does anyone know if checking for the User or Customer Role membership inside ISF / Javascript is supported? -- Like similar to how we can check for "Moment".

If so, what is the variable name and the values?

Thanks.

3 REPLIES
New Member

Based on what I've seen there

Based on what I've seen there doesn't appear to be a JavaScript variable for this, if you view the source you will see only the following exist:

  var Moment = 'ordering';
  var EditRequisitionBeforeOrdering = false;
  var Context = 'MyServices';
  var UserID = '1';
  var ReqCustomerID = '1';
  var ReqInitiatorID = '1';
  var ReqID = '0';
  var ReqEntryID = '0';
  var PricePerUnit  = 1425.75;
  var Quantity  = 1;
  var Bundled = false;
  var TaskID = '0';
  var TaskName  = '';
  var ServiceID  = '553';
  var ServiceName  = 'New Employee On Board';

 

Our approach (and have also seen this used in IAC in a function called checkRole in customcso.js) is to use the NS API to call /RequestCenter/nsapi/directory/currentuser and extract the role attributes from the DOM object

New Member

Thanks for the reply.That

Thanks for the reply.

That sounds like a good option, but unfortunately, that will take me little more time/effort than I thought... I'll have to figure out some other alternative for now.

As a follow up question, in the integration guide, there are examples of using nsAPI from JavaScript Portlets. Do you know if the same libraries etc. will work and supported from the plain ISF / Javascript functions?

 

Thanks.

New Member

I think some of the libraries

I think some of the libraries such as ExtJS are loaded and usable on the order forms, but for ones that are not, you can point to the existing library files under RequestCenter.war and add them as a JavaScript library in service designer.

Below is a quick example of looking up the role through the NS API, it should be enough to get you started on what you need.

 

function doSomething(){
    
    //Performs NS API XHR Request and returns the responseXML document
    function nsapiRequest(url) {
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url, false);
        xhr.send();
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                return xhr.responseXML;
            } else {
                console.error(xhr.statusText);
            }
        }
    }

    //Function to check if user belongs to a role
    function hasRole(roleName) {
        var doc = nsapiRequest("/RequestCenter/nsapi/directory/people/currentuser");
        //Get all associated role elements
        var roles = doc.getElementsByTagName("associatedRole");
            
        //Loop through roles to check for a specific one, could also build an array of all user roles
        for (var i = 0; i < roles.length; i++) {
            //Extract role value
            var role = roles[i].childNodes[1].firstChild.nodeValue;
            if (role === roleName)
                return true;
        }
        return false;
    }

    var siteAdmin = hasRole("Site Administrator");
    if (siteAdmin){
        //do something
    }
}

92
Views
0
Helpful
3
Replies