hi,
I am created a code for comparing the names of two object .which is as below, the portion marked in bold is the main logic. But it is not working properly.
It will be a great help for me if some can suggest me some modification
CODE
var oOutput = Context.createOutputObject()
var xlTableActive=false
oOutput.DefineF(getString("ID_STYLE_RD_INFO"), getString("ID_DEFAULT_FONT"), 14, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_BOLD | Constants.FMT_CENTER| Constants.FMT_VTOP, 0, 0, 1.76, 8.82, 0, 1)
oOutput.DefineF(getString("ID_STYLE_RD_TITLE"), getString("ID_DEFAULT_FONT"), 21, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_BOLD | Constants.FMT_CENTER| Constants.FMT_VTOP, 0, 0, 1.76, 8.82, 0, 1)
oOutput.DefineF(getString("ID_STYLE_RD_DEFAULT"), getString("ID_DEFAULT_FONT"), 11, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_LEFT| Constants.FMT_VTOP, 0, 0, 0, 0, 0, 1)
oOutput.DefineF(getString("ID_STYLE_RD_HEADING_4"), getString("ID_DEFAULT_FONT"), 12, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_ITALIC | Constants.FMT_BOLD | Constants.FMT_LEFT| Constants.FMT_VTOP| Constants.FMT_TOCENTRY3 , 0, 0, 0, 0, 0, 1)
oOutput.DefineF(getString("ID_STYLE_RD_TABLE_CONTENT"), getString("ID_DEFAULT_FONT"), 8, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_LEFT| Constants.FMT_VTOP, 0, 0, 0, 0, 0, 1)
oOutput.DefineF(getString("ID_STYLE_RD_HEADING_3"), getString("ID_DEFAULT_FONT"), 12, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_ITALIC | Constants.FMT_BOLD | Constants.FMT_LEFT| Constants.FMT_VTOP| Constants.FMT_TOCENTRY2 , 0, 0, 1, 1, 0, 1)
oOutput.DefineF(getString("ID_STYLE_RD_HEADER_FOOTER"), getString("ID_DEFAULT_FONT"), 10, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_LEFT| Constants.FMT_VTOP, 0, 0, 0, 0, 0, 1)
oOutput.DefineF(getString("ID_STYLE_RD_HEADING_2"), getString("ID_DEFAULT_FONT"), 14, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_ITALIC | Constants.FMT_BOLD | Constants.FMT_LEFT| Constants.FMT_VTOP| Constants.FMT_TOCENTRY1 , 0, 0, 2, 2, 0, 1)
oOutput.DefineF(getString("ID_STYLE_RD_HEADING_1"), getString("ID_DEFAULT_FONT"), 18, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_BOLD | Constants.FMT_LEFT| Constants.FMT_VTOP| Constants.FMT_TOCENTRY0 , 0, 0, 4, 4, 0, 1)
oOutput.DefineF(getString("ID_STYLE_RD_TABLE_HEAD"), getString("ID_DEFAULT_FONT"), 8, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_BOLD | Constants.FMT_CENTER| Constants.FMT_VTOP, 0, 0, 0, 0, 0, 1)
setupOutputObject( oOutput )
oOutput.SetTitle(Context.getScriptInfo(Constants.SCRIPT_NAME))
var nLocale = Context.getSelectedLanguage()
createSection1(oOutput, ArisData.getSelectedModels())
oOutput.WriteReport()
function setupOutputObject(outputObj)
{
outputObj.SetPageWidth(210.1)
outputObj.SetPageHeight(297.2)
outputObj.SetLeftMargin(20)
outputObj.SetRightMargin(20)
outputObj.SetTopMargin(30)
outputObj.SetBottomMargin(30)
outputObj.SetDistHeader(10)
outputObj.SetDistFooter(10)
outputObj.SetAutoTOCNumbering(true)
globalHeader(outputObj)
globalFooter(outputObj)
}
function globalHeader(outputObj) {
outputObj.BeginHeader()
if(Context.getSelectedFormat()!=Constants.OUTEXCEL)
outputObj.BeginTable(100, Constants.C_TRANSPARENT, Constants.C_TRANSPARENT, Constants.FMT_LEFT | Constants.FMT_NOBORDER, 0)
outputObj.TableRow()
outputObj.ResetFrameStyle()
outputObj.SetFrameStyle( Constants.FRAME_TOP, 0, 0)
outputObj.SetFrameStyle( Constants.FRAME_LEFT, 0, 0)
outputObj.SetFrameStyle( Constants.FRAME_BOTTOM, 0, 0)
outputObj.SetFrameStyle( Constants.FRAME_RIGHT, 0, 0)
outputObj.TableCell("", 50, getString("ID_DEFAULT_FONT"), 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_VTOP | Constants.FMT_LEFT, 0)
outputObj.BeginParagraph( Constants.FMT_LEFT, 0.71, 0.71, 0, 0, 0)
outputObj.OutputLn(Context.getScriptInfo(Constants.SCRIPT_NAME), getString("ID_DEFAULT_FONT"), 12, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_LEFT, 0.71)
outputObj.EndParagraph()
outputObj.TableCell("", 50, getString("ID_DEFAULT_FONT"), 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_VTOP | Constants.FMT_RIGHT, 0)
outputObj.BeginParagraph( Constants.FMT_RIGHT, 0.71, 0.71, 0, 0, 0)
outputObj.OutputField(Constants.FIELD_FILENAME, getString("ID_DEFAULT_FONT"), 12, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_RIGHT)
outputObj.OutputLn("", getString("ID_DEFAULT_FONT"), 12, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_RIGHT, 0.71)
outputObj.EndParagraph()
if(Context.getSelectedFormat()!=Constants.OUTEXCEL)
outputObj.EndTable("", 100, getString("ID_DEFAULT_FONT"), 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT, 0)
else
outputObj.TableRow()
outputObj.EndHeader()
}
function globalFooter(outputObj) {
outputObj.BeginFooter()
if(Context.getSelectedFormat()!=Constants.OUTEXCEL)
outputObj.BeginTable(100, Constants.C_TRANSPARENT, Constants.C_TRANSPARENT, Constants.FMT_LEFT | Constants.FMT_NOBORDER, 0)
outputObj.TableRow()
outputObj.ResetFrameStyle()
outputObj.SetFrameStyle( Constants.FRAME_TOP, 0, 0)
outputObj.SetFrameStyle( Constants.FRAME_LEFT, 0, 0)
outputObj.SetFrameStyle( Constants.FRAME_BOTTOM, 0, 0)
outputObj.SetFrameStyle( Constants.FRAME_RIGHT, 0, 0)
outputObj.TableCell("", 50, getString("ID_DEFAULT_FONT"), 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_VTOP | Constants.FMT_LEFT, 0)
outputObj.BeginParagraph( Constants.FMT_LEFT, 0.71, 0.71, 0, 0, 0)
outputObj.OutputField(Constants.FIELD_DATE, getString("ID_DEFAULT_FONT"), 10, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_LEFT)
outputObj.OutputLn("", getString("ID_DEFAULT_FONT"), 10, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_LEFT, 0.71)
outputObj.EndParagraph()
outputObj.TableCell("", 50, getString("ID_DEFAULT_FONT"), 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_VTOP | Constants.FMT_RIGHT, 0)
outputObj.BeginParagraph( Constants.FMT_RIGHT, 0.71, 0.71, 0, 0, 0)
outputObj.Output(getString("ID_REPORTDEF_2"), getString("ID_DEFAULT_FONT"), 10, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_RIGHT, 0.71)
outputObj.OutputField(Constants.FIELD_PAGE, getString("ID_DEFAULT_FONT"), 10, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_RIGHT)
outputObj.Output(getString("ID_REPORTDEF_3"), getString("ID_DEFAULT_FONT"), 10, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_RIGHT, 0.71)
outputObj.OutputField(Constants.FIELD_NUMPAGES, getString("ID_DEFAULT_FONT"), 10, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_RIGHT)
outputObj.OutputLn("", getString("ID_DEFAULT_FONT"), 10, RGB(0,0,0), Constants.C_TRANSPARENT, Constants.FMT_RIGHT, 0.71)
outputObj.EndParagraph()
if(Context.getSelectedFormat()!=Constants.OUTEXCEL)
outputObj.EndTable("", 100, getString("ID_DEFAULT_FONT"), 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT, 0)
else
outputObj.TableRow()
outputObj.EndFooter()
}
function createSection1(p_output, p_aModel)
{
// do not create new section if all data is empty
if(p_aModel.length==0)
return
//produce one table sheet per section
if(xlTableActive && Context.getSelectedFormat()==Constants.OUTEXCEL) {
p_output.EndTable("", 100, "", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT, 0)
xlTableActive=false
}
p_output.BeginSection(false, Constants.SECTION_DEFAULT)
setupOutputObject( p_output ) //use defaults
if(Context.getSelectedFormat()==Constants.OUTEXCEL) {
p_output.BeginTable(100, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT | Constants.FMT_REPEAT_HEADER, 0)
xlTableActive=true
}
// repetition of queried data:
for(var i=0; i<p_aModel.length; i++) {
iteration_group(p_output, p_aModel[i].ObjDefList())
}
// createSection1 local functions:
/**
* @param {Output} p_output The output object
* @param {ObjDef[]} p_aObjDef
*/
function iteration_group(p_output, p_aObjDef)
{
var il,il2;
// repetition of queried data:
for( i1=0; i1<p_aObjDef.length; i1++) {
p_output.BeginParagraphF(getString("ID_STYLE_RD_DEFAULT"))
for(i12=il+1; i12<p_aObjDef.length; i12++){
if(p_aObjDef[i1]==p_aObjDef[i12])
{ writeData(p_output, p_aObjDef[i1].Name(nLocale))
p_output.EndParagraph()
}
}
}
// iteration_group local functions:
/**
* @param {Output} p_output The output object
* @param {String } p_String
*/
function writeData(p_output, p_String) {
p_output.OutputLnF(p_String, getString("ID_STYLE_RD_DEFAULT"))
}
}
if(Context.getSelectedFormat()==Constants.OUTEXCEL) {
p_output.EndTable(getString("ID_REPORTDEF_5"), 100, "", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT, 0)
xlTableActive=false
}
p_output.EndSection()
}
function RGB(r, g, b) {
return (new java.awt.Color(r/255.0,g/255.0,b/255.0,1)).getRGB() & 0xFFFFFF
}
Hi,
well, you are just comparing two object definitions ObjDef1 == ObjDef2. So this will never be the same...
You have to compare the names:
oObjDef1.Name(nLocale) == oObjDef2.Name(nLocale)
Or you could use a map:
var mObjectNames = new java.util.Hashtable();
for (i = 0; i < oObjDefList.lenght; i++){
oObjDef = oObjDefList[i];
if (mObjectNames.containsKey(oObjDef.Name(nLocale))){
// output
oOtherObjDef = mObjectNames.get(oObjDef.Name(nLocale));
}
mObjectNames.put(oObjDef.Name(nLocale), oObjDef)
}
BR Robert
Hi Robert,
Thanks for the inputs but its still not working. I have modified my code as below
function iteration_group(p_output, p_aObjDef)
{
for( var x=0;x<p_aObjDef.length;x++)
{
p_output.BeginParagraphF(getString("ID_STYLE_RD_DEFAULT"))
for(var y=x+1; y<p_aObjDef.length; y++)
{
if(p_aObjDef[x].Name(nLocale)==p_aObjDef[y].Name(nLocale))
{ writeData(p_output, p_aObjDef[x].Name(nLocale))
p_output.EndParagraph()
}
}
}
Hm, well it works for me - please use the script below to test it - if you ever get to a = 1, it works correctly... Perhaps you have something wrong with your output object ?
function main(){
p_aObjDef= ArisData.getSelectedObjDefs()
nLocale = Context.getSelectedLanguage()
for( var x=0;x<p_aObjDef.length;x++){
for(var y=x+1; y<p_aObjDef.length; y++){
if(p_aObjDef[x].Name(nLocale)==p_aObjDef[y].Name(nLocale)){
a = 1
}
}
}
}
main()
Hi,
A String is a java object in aris and not a primitive like Int or long so you should use "equals" function to compare the names, it works better.
If you compare two strings, use "equals" function :
if(objdef1.Name(lng).equals(objdef2.Name(lng))){
//Code here
}