Here is a sample code to retrieve the Rules that are specified for a Particular user group in AX 2009. As in table it will stores as a BLOB. The following code will return the RLS rules in JSON Format....
Just pass the AX User Group Name as a parameter...
public str RecordLevelSecurity(str 100 Groupid)
{
SysQueryRun queryRun;
Query query = new Query();
QueryBuildRange range;
sysRecordLevelSecurity sys;
int i,cnt,j=0;
str tablename,result,id,temptablename;
result+="{";
while select * from sys where sys.groupId==Groupid
if (sys.RecId)
{
if (sys.Restriction)
{
queryRun = new SysQueryRun(sys.Restriction);
}
else
{
query.addDataSource(sys.TabId);
queryRun = new SysQueryRun(query);
}
queryRun.saveUserSetup(false);
queryRun.promptAllowAddDataSource(false);
cnt = queryRun.query().dataSourceTable(sys.tabId).rangeCount();
if(j>0)
result+=",";
for (i=1 ; i<=cnt; i++)
{
range = queryRun.query().dataSourceTable(sys.tabId).range(i);
if(i==1)
{
tablename=tableid2name(sys.tabId);
result+='"'+tablename+'"';
result+=":";
result+="{";
result+='"'+range.AOTname()+'"';
result+=":";
result+='"'+range.value()+'"';
}
else
{
result+=",";
result+='"'+range.AOTname()+'"';
result+=":";
result+='"'+range.value()+'"';
}
j++;
}
result+="}";
}
result+="}";
return result;
}