web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Javascript SOAP call on Database permissions

(0) ShareShare
ReportReport
Posted on by

Hello,

Can anyone point me what might be the permissions to execute javascript SOAP calls on the CRM Database?

I am a Sys Admin and I can execute na onSave SOAP call just fine (the code is working fine) but the other users can't.

I've been tampering with the permissions but I can't seem to make it work for others. I know it's not my Windows Authenticated user, since if I remove the Sys Admin I also can't run the JS properly. It turns but the SOAP call doesn't return the roles I need.

If anyone needs the code I'll be happy to provide it.

Thanks in advance.

 

 

*This post is locked for comments

I have the same question (0)
  • Andre Margono Profile Picture
    2,602 on at

    Hi, could you please provide the code to check what kind of request that you are executing.

  • Community Member Profile Picture
    on at

    Sure. The customization is on a custom entity and I'm retrieving a list of roles for the user chosen on the lookup field.

    var iduser = crmForm.all.userid.DataValue[0].id;
    
    var funcao = crmForm.all.funcao.SelectedText;
    
    
     //*********************************************************
        gIsArray = function(obj) {
            return obj.constructor == Array;
        }
    
        //*********************************************************
        gNullToString = function(strInput){
            if(strInput+"" == "null" || strInput+"" == "undefined"){return "";}
            return strInput;
        }
    
    gIsAuthorizedForRoles = function(roles, userid){  
    
        if (!gIsArray(roles)){
            arrRoles = new Array();
            arrRoles[0] = roles;
        }
        else{
            arrRoles = roles;
        }
        userid = gNullToString(userid);
        var xml = getUserRoles(userid);
        if(xml != null){
            var xmlNodes = xml.selectNodes("//BusinessEntity/q1:name");
            if(xmlNodes != null ){
                //First loop through all securuty roles for the user
                for( i = 0; i < xmlNodes.length; i++){
                    //Now, loop through the requested roles (array)
                    for (var j = 0; j < arrRoles.length; j++) {
                        if (xmlNodes[i].text.toUpperCase()==arrRoles[j].toUpperCase()){
                            return true;  
                            break;
                        }
                    }
                }            
            }
        }
        return false;
     //******************************************************
     function getUserRoles(userid){
    
      var xml = "<?xml version='1.0' encoding='utf-8'?>"+
      "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
      " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
      " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
      GenerateAuthenticationHeader() +
      "<soap:Body>"+
      "<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
      "<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'"+
      " xsi:type='q1:QueryExpression'>"+
      " <q1:EntityName>role</q1:EntityName>" +
      " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
      " <q1:Attributes>" +
      " <q1:Attribute>name</q1:Attribute>" +
      " </q1:Attributes>" +
      " </q1:ColumnSet>" +
      " <q1istinct>false</q1istinct>" +
      " <q1:LinkEntities>" +
      " <q1:LinkEntity>" +
      " <q1:LinkFromAttributeName>roleid</q1:LinkFromAttributeName>" +
      " <q1:LinkFromEntityName>role</q1:LinkFromEntityName>" +
      " <q1:LinkToEntityName>systemuserroles</q1:LinkToEntityName>" +
      " <q1:LinkToAttributeName>roleid</q1:LinkToAttributeName>" +
      " <q1:JoinOperator>Inner</q1:JoinOperator>" +
      " <q1:LinkEntities>" +
      " <q1:LinkEntity>" +
      " <q1:LinkFromAttributeName>systemuserid</q1:LinkFromAttributeName>" +
      " <q1:LinkFromEntityName>systemuserroles</q1:LinkFromEntityName>" +
      " <q1:LinkToEntityName>systemuser</q1:LinkToEntityName>" +
      " <q1:LinkToAttributeName>systemuserid</q1:LinkToAttributeName>" +
      " <q1:JoinOperator>Inner</q1:JoinOperator>" +
      " <q1:LinkCriteria>" +
      " <q1:FilterOperator>And</q1:FilterOperator>" +
      " <q1:Conditions>" +
      " <q1:Condition>" +
      " <q1:AttributeName>systemuserid</q1:AttributeName>";
    
      userid = gNullToString(userid);
      if (userid == ''){
       xml +=  " <q1:Operator>EqualUserId</q1:Operator>";
      }
      else{   
       xml +=  " <q1:Operator>Equal</q1:Operator>" + 
            " <q1:Values>" + 
            " <q1:Value xsi:type=\"xsd:string\">" + userid + "</q1:Value>" + 
            " </q1:Values>";   
      }
    
      xml +=
      " </q1:Condition>" +
      " </q1:Conditions>" +
      " </q1:LinkCriteria>" +
      " </q1:LinkEntity>" +
      " </q1:LinkEntities>" +
      " </q1:LinkEntity>" +
      " </q1:LinkEntities>" +
      "</query>"+
      "</RetrieveMultiple>"+
      "</soap:Body>"+
      "</soap:Envelope>";
        
      var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
      xmlHttpRequest.Open("POST", '/mscrmservices/2007/CrmService.asmx', false);
      xmlHttpRequest.setRequestHeader("SOAPAction",'http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple');
      xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
      xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
      xmlHttpRequest.send(xml);
    
      //Capture and return the xml result.
      var resultXml = xmlHttpRequest.responseXML;
      return resultXml;
     }
       
    }
    
    if(funcao == 'Gestor')
    {
    if(gIsAuthorizedForRoles(['Gestor de Projecto'], iduser))
    {
    //DO NOTHING
    }
    else
    {
    alert('Some text');
    event.returnValue = false;
    return false;
    }
    }

  • Andre Margono Profile Picture
    2,602 on at

    Hi by the look of the code it seems you are working on CRM 4.0, is that correct?

    I couldn't reproduce the code, as I don't have CRM 4.0 instance anymore, however from the code it seems you are trying to retrieve security role. Try to give permission on: "prvReadRole" (Business Management > Security Role) to the user to be able to read/query security role.

  • Community Member Profile Picture
    on at

    Yes it's CRM 4 . I tagged it as CRM 4, sorry if it didn't show up.

    I already have read permissions for Security Role. Don't have Create/Write/Delete but I don't think they're necessary. Could be wrong though.

  • Verified answer
    Andre Margono Profile Picture
    2,602 on at

    From memory if you enable tracing you could list-up the missing privileges. These 'oldies but goodies' articles describe on how to troubleshoot it: technet.microsoft.com/.../2009.08.dynamics.aspx

    and blogs.msdn.com/.../how-to-troubleshoot-permissions-issue.aspx

  • Community Member Profile Picture
    on at

    I already tried tracing it. The problem is it doesn't throw a stack. In fact it doesn't even throw an error.

    It just doesn't return anything from the SOAP call.

    But I will try what you linked.

  • Verified answer
    Community Member Profile Picture
    on at

    It turned out to be the "Associate" option for the User entity. I'm still a bit unsure to why it needs that permission but it fixed it.

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans