This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Item Report-Display or hide a row based on condition

meenu - Monday, July 22, 2013 2:43 AM:

Hi,

How can I hide or display a row on report based on a condition. I have a drop down on my item with 'Direct' and 'Indirect' as values. If I select 'Direct' I need to fill another four fields related to it, If I select 'Indirect' I need to fill another 4 fields which are different from 'Direct' Fields . 

I have created two rows, one for 'Direct' fields and second for 'Indirect' 4 fields on the report.  If I select 'Direct' I will fill its related fields and will not fill the 'Indirect' fields. So, in this case no need to display the 'Indirect' fields row on the report . 

For ex: I need to fill 1,2,3,4 fields if value of drop down is 'Direct' and 5,6,7,8 fields if it is 'Indirect'. All the 8 fields will be there on the form but on report only four (either 1,2,3,4 or 5,6,7,8) should be there.

Need to display only one row at a time. How can I do this? Can we do this with HTML? Please help me

Thank you



meenu - Thursday, July 25, 2013 6:28 AM:

I tried the following JS function in the Stylesheet . I'm able to hide the table/row using this function. I'm calling this function using setInterval(function(){ toggle();}, 100); . 

function toggle()

{

 //var stat = document.getElementById("stat");

var stat = "Direct";                                                                                                                                                                                                                                                         var tabels = document.getElementsByTagName('table');

if(stat==="Direct"){                                                                                                                                                                                                                                                 for(var i = tabels.length; i-- ;) {

        var tabel = tabels[i];

        if(tabel.className === 'row5') { tabel.style.display = 'none'; }  // hides this <table class="row5">

}} else{

    for(var j = tabels.length; j-- ;) {

        var tabel1 = tabels[j];

        if(tabel1.className === 'row4') {  tabel1.style.display = 'none'; }

} }

}

But  I'm facing problem with getting the property value. I tried document.thisItem.getProperty("stat"); and document.getElementById("stat");   both are not getting the property value.
How can I get the property value here in the function? 


Brian - Thursday, July 25, 2013 10:05 PM:

Hi MK,

Have you tried just using an xsl:if statement in the stylesheet?

That way you can test for the "Direct" or "Indirect" value and only create the fields you need based on the result.

It is probably cleaner than trying to hide some part of the report dynamically.

Hope this helps,

Brian.



meenu - Monday, July 29, 2013 1:15 AM:

Hi Brian,

Thank you for suggesting a simple solution. It worked.

Isn't there a way to get the property value on the report as I asked earlier?

Thank you 



Brian - Monday, July 29, 2013 1:33 AM:

Hi MK,

I'm not sure where in the process you are trying to get the property value.

Is this in the xslt transform or while in a javascript method for the report or in a javascript method on a form?

Have a look at the programmers guide for the Context item. It changes depending on where you are calling code from.

http://www.aras.com/support/documentation/ 

There are also examples of retrieving values from forms etc.

Get back to me with some more information on what you are trying to do with a little more context, if this doesn't help.

Cheers,

Brian.

 



meenu - Monday, July 29, 2013 6:03 AM:

Hi Brian, I checked the Programmers Guide, it says add '_system' as suffix to the property name. But still it is not getting the value.

I defined the function in the Report's Stylesheet like below: 

Here I am mentioning just a code fragment from Report Stylesheet not the entire code.

<xsl:stylesheet version="1.0" xmlns:xsl="www.w3.org/.../Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:user-scripts" xmlns:aras="http://www.aras.com">

<xsl:template match="Item[@type='Test']">
    <html>
      <head>
        <title>Test Report</title>
        </head>
       <script type="text/javascript">function toggle() {
                var stat = document.getElementById("stat_system");
                var temp = stat.value;
                
                //var stat = "Direct";                                                                                                                                                                                                                                                         
                var tabels = document.getElementsByTagName('table');

                if(temp === "Direct"){                                                                                                                                                                                                                                                 
                for(var i = tabels.length; i-- ;) {
                var tabel = tabels[i];
                if(tabel.className === 'row5') { tabel.style.display = 'none'; }  
                }} else{
                for(var j = tabels.length; j-- ;) {
                var tabel1 = tabels[j];
                if(tabel1.className === 'row4') {  tabel1.style.display = 'none'; }
                } }
                }
         setInterval(function(){ toggle();}, 100);
        </script>
<!-- Tables -->
<table class="row4">
          <tr>
          </tr>
</table> 
<table class="row5">
          <tr>
          </tr>
</table>
</html>
</xsl:template>
</xsl:stylesheet>


Here 'stat' is the property name. I added the 'stat' field as a dropdown with 'Direct' & 'Indirect' as values on the 'Test' Itemtype's default form. 

1)Can we get property values from stylesheet ?

2)How can I get value If the form on which the 'stat' field resides is an independent  form which is added as a Relationship view for a NoRelated relationship of same Itemtype(Test). Field's datasource is still the same property of Test Itemtype. 

Thank you.



Brian - Wednesday, July 31, 2013 9:02 PM:

Hi MK,

document.getElementById( ) isn't going to work in the stylesheet because the context in here is the xml that is being transformed.

You need to ensure that the stat value is included in the xml that will get handed to the stylesheet and then you can access it as an xsl:select

Also if you can include the stat value in the xml then you don't need to "hide" the row based on the value you just use an in-line xsl:if statement to decide which lines you actually put into the report. That is the beauty of xslt you take the xml and transform it to only what you need it to be.

Cheers,

Brian.