When we are working with Dynamics CRM and writing the client application using Java to establish the connection and executing the Stub, there might be situation where we need obtain EntityType of GUID dynamically. Use the following class and instantiate to obtain the EntityType of GUID.
import java.rmi.RemoteException;
import java.util.ArrayList;
import com.microsoft.schemas.crm._2006.Query.AllColumns;
import com.microsoft.schemas.crm._2007.WebServices.RetrieveRequest;
import com.microsoft.schemas.crm._2007.WebServices.RetrieveResponse;
import com.microsoft.schemas.crm._2007.WebServices.TargetRetrieveDynamic;
import com.microsoft.wsdl.types.Guid;
public class GetEntityType {
public String getGuidType(String id) {
//Add the Entity to the "type" ArrayList, I had some samples.
ArrayList<String> type= new ArrayList<String>();
type.add("account");
type.add("contact");
type.add("lead");
type.add("queue");
type.add("user");
type.add("facility/equipment");
String entityType=null;
TargetRetrieveDynamic target = new TargetRetrieveDynamic();
RetrieveResponse response = null;
for(String t : type)
{
target.setEntityName(t.toString());
target.setEntityId(new Guid(id));
AllColumns columnSet = new AllColumns();
RetrieveRequest ret = new RetrieveRequest();
ret.setTarget(target);
ret.setColumnSet(columnSet);
ret.setReturnDynamicEntities(true);
try {
Object servicetype;
if (servicetype.equals("OnPremise")) {
//For OnPremise Account use Onpremise BindingStub
response = (RetrieveResponse) this.bindingStubOnPremise.execute(ret);
}
else {
//For Online Account use Online Account
response = (RetrieveResponse) this.bindingStubOnline.execute(ret);
}
} catch (RemoteException e) {
continue;
}
if(response!=null)
{
entityType = t;
break;
}
}
return entityType;
}
}
...Prabakaran
No comments:
Post a Comment