CRM 2011 : Set Picklist values via MetadataService using Java

1

I've gotten the task to set (and get) values for a Picklist on a CRM2011 system using Java.

I've generated a client classes for both crmservice.wsdl and metadataservice.wsdl, using wsdl2java with CXF 2.5 which for crmservice.wsdl gave me the ability to add accounts and products.

When i try using the metadataservice i only end up getting "Server was unable to process request. ---> Url does not contain MSCRMServices or XRMServices"

Heres a client where i'm just trying to get a Picklist:

public class MetaDataServiceStarter {
protected final Logger logger = Logger.getLogger(getClass());

private static GlobalMetadataConnector globCon = GlobalMetadataConnector.instance();

public static void main(String[] args) {
    Run();
}

public static void Run(){
    // Adds a option called Zimbabwe to fs_country picklist in account entity
    AddPicklistOption("account", "fs_country", "Rikipiki Reisch", 717610017, 1033);
}

private static void AddPicklistOption(String sEntity, String sAttribute, String sLabel, int iValue, int iLanguage) {
    // TODO Auto-generated method stub
    if(!PicklistOptionExist(sEntity, sAttribute, iValue)){
        CreatePicklistOption(sEntity, sAttribute, sLabel, iValue, iLanguage);
    }

}

private static void CreatePicklistOption(String sEntity, String sAttribute, String sLabel, int iValue, int iLanguage) {
    // TODO Auto-generated method stub
    CrmLabel crmLabel = new CrmLabel();
    LocLabel crmLocLabel = new LocLabel();
    ArrayOfLocLabel arrayOfLocLabel = new ArrayOfLocLabel();

    CrmNumber crmLanguage = new CrmNumber(); //Only available in 2006!!!
    crmLanguage.setValue(iLanguage);
    crmLocLabel.setLanguageCode(crmLanguage);
    crmLocLabel.setLabel(sLabel);
    ArrayOfLocLabel locLabel = new ArrayOfLocLabel();
    crmLabel.setLocLabels((ArrayOfLocLabel) locLabel.getLocLabel() ); //crmLabel.LocLabels = new LocLabel[] { crmLocLabel };
    InsertOptionValueRequest insertRequest = new InsertOptionValueRequest();
    insertRequest.setAttributeLogicalName(sAttribute);
    insertRequest.setEntityLogicalName(sEntity);
    insertRequest.setLabel(crmLabel);
    CrmNumber crmValue = new CrmNumber();
    crmValue.setValue(iValue);
    insertRequest.setValue(crmValue);

    InsertOptionValueResponse insertResponse = (InsertOptionValueResponse) globCon.getSvc().execute(insertRequest, globCon.getToken(), null );

                                                                                                  //request, crmAuthenticationToken, callerOriginToken, correlationToken)
            //(insertRequest, globCon.getToken(), globCon.getToken()., correlationToken)
            //.Execute(insertRequest);

}

private static boolean PicklistOptionExist(String sEntity, String sAttribute, int iValue) {
    RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();
    attributeRequest.setEntityLogicalName(sEntity);
    attributeRequest.setLogicalName(sAttribute);
    attributeRequest.setRetrieveAsIfPublished(true);

    RetrieveAttributeResponse response = (RetrieveAttributeResponse) globCon.getSvc().execute(attributeRequest, globCon.getToken(), null);
    PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.getAttributeMetadata();


    return true;

       // response = (RetrieveAttributeResponse) globCon.getSvc().execute(request, globCon.getToken(), null);
}

}

Client creates the following request:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <CrmAuthenticationToken xmlns:ns3="http://schemas.microsoft.com/crm/2007/CoreTypes" xmlns:ns2="http://schemas.microsoft.com/crm/2009/WebServices" xmlns="http://schemas.microsoft.com/crm/2007/WebServices">
      <ns3:AuthenticationType>0</ns3:AuthenticationType>
      <ns3:OrganizationName>SomeCompanyCountryStaging</ns3:OrganizationName>
      <ns3:CallerId>00000000-0000-0000-0000-000000000000</ns3:CallerId>
    </CrmAuthenticationToken>
  </soap:Header>
  <soap:Body>
    <Execute xmlns="http://schemas.microsoft.com/crm/2007/WebServices" xmlns:ns2="http://schemas.microsoft.com/crm/2009/WebServices" xmlns:ns3="http://schemas.microsoft.com/crm/2007/CoreTypes">
      <Request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RetrieveAttributeRequest">
        <EntityLogicalName>account</EntityLogicalName>
        <LogicalName>fs_country</LogicalName>
        <RetrieveAsIfPublished>true</RetrieveAsIfPublished>
      </Request>
    </Execute>
  </soap:Body>
</soap:Envelope>

And this is the response i get: soap:Server Server was unable to process request. 0x80040203 Url does not contain MSCRMServices or XRMServices Platform

Has anyone had success getting or setting a Picklist or even doing anything with the MatadataService via Java?

java
cxf
dynamics-crm-2011
asked on Stack Overflow Dec 15, 2011 by Infini • edited May 9, 2012 by NickGreen

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0