Skip to main content
added 33 characters in body
Source Link
Santanu Boral
  • 36.2k
  • 8
  • 45
  • 72

You have to build the logic like this.

  1. Find Previous owner and Current Owner 2. Verify if previous owner is a 'Queue' 3. If point 2 satisfies then find the current user is part of that queue. 4. If point 3 satisfies then allow update the ownership, otherwise throw the error message. 5. Also, wise to check, if current and previous owner are not same.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
var caseObj = new sforce.SObject("Case"); 
var previousOwner = "{!Case.OwnerId}"; 
var currentOwner = "{!$User.Id}"; 
caseObj.Id = "{!Case.Id}"; 
caseObj.OwnerId = "{!$User.Id}"; 
caseObj.Status = 'Working';

//if previousOwner is queue 
var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Case where owner.type= 'Queue' AND OwnerId='"+ previousOwner + "' AND Id='" + caseObj.Id + "'"); 
var records1 = ownerRec.getArray('records');
if(records1 !=null && records1.length>0)
{   
    //currentOwner is part of queue
    var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
    var records2 = currentOwnerRec.getArray('records');
    
    if(records2 !=null && records2.length>0)
    {
        var result = sforce.connection.update([caseObj]);   
        location.reload();  
    }
    else
    {
        alert("You cannot take this case because you are not part of the queue");
    }
}
if(previousOwner == currentOwner) 
{   
    alert("You are already the Case Owner ");   
}

You have to build the logic like this.

  1. Find Previous owner and Current Owner 2. Verify if previous owner is a 'Queue' 3. If point 2 satisfies then find the current user is part of that queue. 4. If point 3 satisfies then allow update the ownership, otherwise throw the error message. 5. Also, wise to check, if current and previous owner are not same.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
var caseObj = new sforce.SObject("Case"); 
var previousOwner = "{!Case.OwnerId}"; 
var currentOwner = "{!$User.Id}"; 
caseObj.Id = "{!Case.Id}"; 
caseObj.OwnerId = "{!$User.Id}"; 

//if previousOwner is queue 
var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Case where owner.type= 'Queue' AND OwnerId='"+ previousOwner + "' AND Id='" + caseObj.Id + "'"); 
var records1 = ownerRec.getArray('records');
if(records1 !=null && records1.length>0)
{   
    //currentOwner is part of queue
    var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
    var records2 = currentOwnerRec.getArray('records');
    
    if(records2 !=null && records2.length>0)
    {
        var result = sforce.connection.update([caseObj]);   
        location.reload();  
    }
    else
    {
        alert("You cannot take this case because you are not part of the queue");
    }
}
if(previousOwner == currentOwner) 
{   
    alert("You are already the Case Owner ");   
}

You have to build the logic like this.

  1. Find Previous owner and Current Owner 2. Verify if previous owner is a 'Queue' 3. If point 2 satisfies then find the current user is part of that queue. 4. If point 3 satisfies then allow update the ownership, otherwise throw the error message. 5. Also, wise to check, if current and previous owner are not same.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
var caseObj = new sforce.SObject("Case"); 
var previousOwner = "{!Case.OwnerId}"; 
var currentOwner = "{!$User.Id}"; 
caseObj.Id = "{!Case.Id}"; 
caseObj.OwnerId = "{!$User.Id}"; 
caseObj.Status = 'Working';

//if previousOwner is queue 
var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Case where owner.type= 'Queue' AND OwnerId='"+ previousOwner + "' AND Id='" + caseObj.Id + "'"); 
var records1 = ownerRec.getArray('records');
if(records1 !=null && records1.length>0)
{   
    //currentOwner is part of queue
    var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
    var records2 = currentOwnerRec.getArray('records');
    
    if(records2 !=null && records2.length>0)
    {
        var result = sforce.connection.update([caseObj]);   
        location.reload();  
    }
    else
    {
        alert("You cannot take this case because you are not part of the queue");
    }
}
if(previousOwner == currentOwner) 
{   
    alert("You are already the Case Owner ");   
}
deleted 154 characters in body
Source Link
Santanu Boral
  • 36.2k
  • 8
  • 45
  • 72

You have to build the logic like this.

  1. Find Previous owner and Current Owner 2. Verify if previous owner is a 'Queue' 3. If point 2 satisfies then find the current user is part of that queue. 4. If point 3 satisfies then allow update the ownership, otherwise throw the error message. 5. Also, wise to check, if current and previous owner are not same.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
var ownershipChangeRequestcaseObj = new sforce.SObject("Case"); 
var previousOwner = "{!Case.OwnerId}"; 
var currentOwner = "{!$User.Id}"; 
ownershipChangeRequestcaseObj.Id = "{!Case.Id}"; 
ownershipChangeRequestcaseObj.OwnerId = "{!$User.Id}"; 

//if previousOwner is queue 
var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Case where owner.type= 'Queue' AND OwnerId='"+ previousOwner + "' AND Id='" + ownershipChangeRequestcaseObj.Id + "'"); 
var records1 = ownerRec.getArray('records');
if(records1 !=null && records1.length>0)
{   
    //alert(records1);
    //currentOwner is part of queue
    var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
    var records2 = currentOwnerRec.getArray('records');
    //alert(records2);
    if(records2 !=null && records2.length>0)
    {
        //alert('update ownership');
        var result = sforce.connection.update([ownershipChangeRequest][caseObj]);    
        location.reload();  
    }
    else
    {
        alert("You cannot take this case because you are not part of the queue");
    }
}
if(previousOwner == currentOwner) 
{   
    alert("You are already the Case Owner ");   
}

You have to build the logic like this.

  1. Find Previous owner and Current Owner 2. Verify if previous owner is a 'Queue' 3. If point 2 satisfies then find the current user is part of that queue. 4. If point 3 satisfies then allow update the ownership, otherwise throw the error message. 5. Also, wise to check, if current and previous owner are not same.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
var ownershipChangeRequest = new sforce.SObject("Case"); 
var previousOwner = "{!Case.OwnerId}"; 
var currentOwner = "{!$User.Id}"; 
ownershipChangeRequest.Id = "{!Case.Id}"; 
ownershipChangeRequest.OwnerId = "{!$User.Id}"; 

//if previousOwner is queue 
var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Case where owner.type= 'Queue' AND OwnerId='"+ previousOwner + "' AND Id='" + ownershipChangeRequest.Id + "'"); 
var records1 = ownerRec.getArray('records');
if(records1 !=null && records1.length>0)
{   
    //alert(records1);
    //currentOwner is part of queue
    var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
    var records2 = currentOwnerRec.getArray('records');
    //alert(records2);
    if(records2 !=null && records2.length>0)
    {
        //alert('update ownership');
        var result = sforce.connection.update([ownershipChangeRequest]);    
        location.reload();  
    }
    else
    {
        alert("You cannot take this case because you are not part of the queue");
    }
}
if(previousOwner == currentOwner) 
{   
    alert("You are already the Case Owner ");   
}

You have to build the logic like this.

  1. Find Previous owner and Current Owner 2. Verify if previous owner is a 'Queue' 3. If point 2 satisfies then find the current user is part of that queue. 4. If point 3 satisfies then allow update the ownership, otherwise throw the error message. 5. Also, wise to check, if current and previous owner are not same.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
var caseObj = new sforce.SObject("Case"); 
var previousOwner = "{!Case.OwnerId}"; 
var currentOwner = "{!$User.Id}"; 
caseObj.Id = "{!Case.Id}"; 
caseObj.OwnerId = "{!$User.Id}"; 

//if previousOwner is queue 
var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Case where owner.type= 'Queue' AND OwnerId='"+ previousOwner + "' AND Id='" + caseObj.Id + "'"); 
var records1 = ownerRec.getArray('records');
if(records1 !=null && records1.length>0)
{   
    //currentOwner is part of queue
    var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
    var records2 = currentOwnerRec.getArray('records');
    
    if(records2 !=null && records2.length>0)
    {
        var result = sforce.connection.update([caseObj]);   
        location.reload();  
    }
    else
    {
        alert("You cannot take this case because you are not part of the queue");
    }
}
if(previousOwner == currentOwner) 
{   
    alert("You are already the Case Owner ");   
}
deleted 82 characters in body
Source Link
Santanu Boral
  • 36.2k
  • 8
  • 45
  • 72
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
    var ownershipChangeRequest = new sforce.SObject("Case"); 
    var previousOwner = "{!Case.OwnerId}"; 
    var currentOwner = "{!$User.Id}"; 
    ownershipChangeRequest.Id = "{!Case.Id}"; 
    ownershipChangeRequest.OwnerId = "{!$User.Id}"; 
    
    //if previousOwner is queue 
    var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Case where owner.type= 'Queue' AND OwnerId='"+ previousOwner + "' AND Id='" + {!CaseownershipChangeRequest.Id} + "'"); 
    var records1 = ownerRec.getArray('records');
    if(records1 !=null)
   && records1.length>0)
{   
        //alert(ownerRec.records.owner.typerecords1);
        if(ownerRec.records.owner.type == 'Queue')
        {
            //currentOwner is part of queue
            var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
            var records2 = currentOwnerRec.getArray('records');
        //alert(records2);
    if(records2 !=null)
       && records2.length>0)
    {
        //alert('update ownership');
        var result = sforce.connection.update([ownershipChangeRequest]);    
                location.reload();  
            }
            else
            {
                alert("You cannot take this case because you are not part of the queue");
            }
        }
    }
    if(previousOwner == currentOwner) 
    {   
        alert("You are already the Case Owner ");   
    }
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
    var ownershipChangeRequest = new sforce.SObject("Case"); 
    var previousOwner = "{!Case.OwnerId}"; 
    var currentOwner = "{!$User.Id}"; 
    ownershipChangeRequest.Id = "{!Case.Id}"; 
    ownershipChangeRequest.OwnerId = "{!$User.Id}"; 
    
    //if previousOwner is queue 
    var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Case where  OwnerId='"+ previousOwner + "' AND Id='" + {!Case.Id} + "'"); 
    var records1 = ownerRec.getArray('records');
    if(records1 !=null)
    {   
        //alert(ownerRec.records.owner.type);
        if(ownerRec.records.owner.type == 'Queue')
        {
            //currentOwner is part of queue
            var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
            var records2 = currentOwnerRec.getArray('records');
            if(records2 !=null)
            {
                var result = sforce.connection.update([ownershipChangeRequest]);    
                location.reload();  
            }
            else
            {
                alert("You cannot take this case because you are not part of the queue");
            }
        }
    }
    if(previousOwner == currentOwner) 
    {   
        alert("You are already the Case Owner ");   
    }
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
var ownershipChangeRequest = new sforce.SObject("Case"); 
var previousOwner = "{!Case.OwnerId}"; 
var currentOwner = "{!$User.Id}"; 
ownershipChangeRequest.Id = "{!Case.Id}"; 
ownershipChangeRequest.OwnerId = "{!$User.Id}"; 

//if previousOwner is queue 
var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Case where owner.type= 'Queue' AND OwnerId='"+ previousOwner + "' AND Id='" + ownershipChangeRequest.Id + "'"); 
var records1 = ownerRec.getArray('records');
if(records1 !=null && records1.length>0)
{   
    //alert(records1);
    //currentOwner is part of queue
    var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
    var records2 = currentOwnerRec.getArray('records');
    //alert(records2);
    if(records2 !=null && records2.length>0)
    {
        //alert('update ownership');
        var result = sforce.connection.update([ownershipChangeRequest]);    
        location.reload();  
    }
    else
    {
        alert("You cannot take this case because you are not part of the queue");
    }
}
if(previousOwner == currentOwner) 
{   
    alert("You are already the Case Owner ");   
}
added 41 characters in body
Source Link
Santanu Boral
  • 36.2k
  • 8
  • 45
  • 72
Loading
deleted 10 characters in body
Source Link
Santanu Boral
  • 36.2k
  • 8
  • 45
  • 72
Loading
Source Link
Santanu Boral
  • 36.2k
  • 8
  • 45
  • 72
Loading