Created On:  04 November 2011

Problem:

Is it possible to add an attribute to a project via the SilkCentral Web Services?

Resolution:

The tmplanning web service provides the addAttributes2 method, which allows a user to add a number of attributes to a specified project, for further information regarding this method see the API Specification. The following code demonstrates how an attribute can be added to a project via the Web Services:


public static void AddAttribute(String sUser, String sPassword){
     try{
          SccsystemSoapBindingStub sccBind = (SccsystemSoapBindingStub)
new SystemServiceServiceLocator().getsccsystem();
          long lSession = sccBind.logonUser(sUser, sPassword);

          TmplanningSoapBindingStub plnBin = (TmplanningSoapBindingStub)
new PlanningServiceServiceLocator().gettmplanning();
          plnBin.setCurrentProject(lSession,
"0"
);

          //Create the attribute to be added
          Attribute2 test = new Attribute2();
          test.setName(
"WebService_Attribute"
);
          test.setDescription(
"A test from WS"
);
          test.setType(
"edit"
);
          test.setActive(
true);
          test.setOptions(new AttributeOption[]{}); //required to prevent NullPointerException

          //Add the attribute(s) to project 0
          plnBin.addAttributes2(lSession, 0,
new Attribute2[]{test});
     }
     catch(Exception e){
          e.printStackTrace();
     }
}


The following attribute types are available:
     - "edit" - Text
     - "normal" - List
     - "set" - List with multi-select
     - "date" - Date
     - "numer" - Number