Skip to Content
0
Jun 15, 2020 at 07:36 PM

Dynamic query to fetch records from successfactors

651 Views

Hi Experts,

I have scenario to fetch records from SuccessFactors(Odata V2). Client has a requirement to fetch all the records if the request xml fields is empty.

And I want to fetch detla records based on RoleID and RoleName, which I am able to do.

I have written a groovy script to achieve this.

My query has some issue as I am able to fetch all the records when I send "space" (in yellow) in RoleID and RoleName.

Please have a look at the script and suggest any correction to achieve the above -

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
    def properties = message.getProperties();
    String RoleId = properties.get("ROLEID");
    String RoleName = properties.get("ROLENAME");
    String query="";
    
    if((RoleId==null || RoleId.trim().length()==0) && (RoleName==null || RoleName.trim().length()==0))
    {
        query="\$select=roleId,roleName";
    }
    if((RoleId==null || RoleId.length()==0) && (RoleName!=null || RoleName.length()>0))
    {
        query="\$select=roleId,roleName&\$filter=roleName eq "+ "'"+RoleName.trim()+"'";
    }
    if((RoleId!=null || RoleId.length()>0) && (RoleName==null || RoleName.length()==0))
    {
        query="\$select=roleId,roleName&\$filter=roleId eq "+RoleId.trim();
    }
    message.setProperty("QUERY_DYNAMIC",query);
    
       return message;
}

Regards,

Akash

Attachments

1.png (10.7 kB)
2.png (70.2 kB)
3.png (40.4 kB)