Project and Portfolio Management Practitioners Forum
cancel

using getRequests to return specific fields

SOLVED
Go to solution
Highlighted
patrick-sa
Super Contributor.

using getRequests to return specific fields

Hi,

 

I'm new to webservices and i' have a requirement to return some specific fields from a request type and this will be used by another application outside of PPM.I can run the method getRequests and this returns all the tokens and field values of the whole request type.How do i filter this so that i return specific fields?

 

Thanks,

Patrick.

4 REPLIES
AlfredoMonasi
Honored Contributor.

Re: using getRequests to return specific fields

Hi Patrick

 

Build your own Web Services using PPM WSDL to return the specific fields you want. You can either use Java or VB.Net to achieve it. Even I think you can use PHP.

 

Regards,

 

Alfredo

patrick-sa
Super Contributor.

Re: using getRequests to return specific fields

Hi Alfredo,

 

Thanks,do you have similar code you can share?just for me to get started?

 

Patrick.

patrick-sa
Super Contributor.
Solution

Re: using getRequests to return specific fields

I've found a way of solving this.This can be still be improved but it works well.

 

 

// get simple fields
final SimpleField[] fields = request.getSimpleFieldsArray();
System.out.println("Simple Fields: " + fields.length);
if (fields.length > 0) {
for (final SimpleField field : fields) {
//System.out.println(" --");
//System.out.println(" Token: " + field.getToken());
final String[] values = field.getStringValue1Array();

switch (field.getToken()){
case "REQ.REQUEST_ID":
System.out.println("Token: " + field.getToken());
for (int j = 0; j < values.length; j++) {
if (j > 0) {
System.out.print("No Data ");
}
System.out.println("Value: " + values[j]);
//System.out.print(values[j]);
}
System.out.println("--");
break;
case "REQ.VP.KNTA_PROJECT_NAME":
System.out.println("Token: " + field.getToken());
for (int j = 0; j < values.length; j++) {
if (j > 0) {
System.out.print("No Data ");
}
System.out.println("Value: " + values[j]);
//System.out.print(values[j]);
}
System.out.println("--");
break;
case "REQ.DESCRIPTION":
System.out.println("Token: " + field.getToken());
for (int j = 0; j < values.length; j++) {
if (j > 0) {
System.out.print("No Data ");
}
System.out.println("Value: " + values[j]);
//System.out.print(values[j]);
}
System.out.println("--");
break;
default:
//System.out.println("No data");
break;
}
System.out.println();
}
}

}
}

}

AlfredoMonasi
Honored Contributor.

Re: using getRequests to return specific fields

You can try this Patrick,

 

Just parse the token you want to get.

 

[WebMethod]
public String obtenerDatosSolicitud(String requestID) {
String resultado = String.Empty;
log.LogMessage("obtenerInfoRequest RequestID: " + requestID);

if (requestID.Equals(String.Empty))
{
resultado="ERROR: El numero de la solicitud no puede ser vacio";
log.LogMessage("obtenerInfoRequest Resultado: " + resultado);
return resultado;
}

try
{
demandaWS = new DemandServiceWse();
UsernameOverTransportAssertion policyAssertion = new UsernameOverTransportAssertion();
// setup WS-Security credentials
policyAssertion.UsernameTokenProvider = new UsernameTokenProvider(ConfigurationManager.AppSettings["userPPM"].ToString(), ConfigurationManager.AppSettings["passPPM"].ToString());
Policy policy = new Policy(policyAssertion);
demandaWS.SetPolicy(policy);

//Request a buscar
DemandService.Identifier[] ids = new DemandService.Identifier[1];
ids[0] = new DemandService.Identifier();
ids[0].id = requestID;

Request[] requestsObtenidos = demandaWS.getRequests(ids);

if (requestsObtenidos.Length > 0){
SimpleField[] fields;
resultado = resultado+requestsObtenidos[0].id;

fields = requestsObtenidos[0].simpleFields;

String[] arreglo;
String token;
//parseando sus valores
for (int i = 0; i < fields.Length; i++) {
arreglo = fields[i].stringValue;
token = fields[i].token;
if (arreglo != null){
resultado = resultado + ConfigurationManager.AppSettings["concatenador"].ToString() + token + "=:" + arreglo[0].ToString();
}
}
}
}
catch (Exception e) {
resultado ="ERROR: "+e.Message;
}

log.LogMessage("obtenerInfoRequest Resultado: " + resultado);
return resultado;
}