Report Template Designer

I'm just wondering if it is possible to create a report that has different rules for populating Data Fields, based on the part number or any other of the fields?

My goal is to create label inscriptions for different pieces of equipment (Relays) and I would like to be able to run a singular report rather than having to run two.

e.g. If my part number is equal to XA100 then use [Data Fields.DeviceTag] in that particular column.

       If my part number is equal to XA110 then use [Data Fields.user6] in the same column.

  • Hi Toby. Yes, this sounds like something you could accomplish with a BeforePrint script. On a template based on a BOM template, you would bind the cell or label where the DeviceTag / user6 value is to appear to a BeforePrint script that would look something like this:

    private void xrLabel2_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
    	string pn = "", u6 = "", tag = "";
    	if (GetCurrentColumnValue("partnumber") != DBNull.Value)
    		pn = (string)GetCurrentColumnValue("partnumber");
    	if (GetCurrentColumnValue("user6") != DBNull.Value)
    		u6 = (string)GetCurrentColumnValue("user6");
    	if (GetCurrentColumnValue("DeviceTag") != DBNull.Value)
    		tag = (string)GetCurrentColumnValue("DeviceTag");
    
    	if (pn == "XA110")
    		(sender as XRLabel).Text = u6;
    	else
    		(sender as XRLabel).Text = tag;
    }
    

    See the Before Print scripts for report templates article for details on where to paste in the script and how to bind it to the cell/label.

    You may need to add some "else if" lines for additional behavior for other part numbers.

    Toby.zip



    Answer Verified By: Toby77 

  • Matt,

    Firstly thank you for pointing me in the right direction, much appreciated. At first I wasn't able to figure out why the script wasn't running.

    I had an issue whereby I tried to run the report on a current project and it simply wouldn't populate the data fields, which made me think the script wasn't working, so then I decided to create a new project from scratch and then placed down a few symbols with a couple of different part numbers and the script and report ran perfectly?

    I'm trying to make the report look exactly like previous versions produced, so people don't freak out about change!

    I  managed to make a couple of adjustments to the script and added an additional data field (function text)

    I'm just wondering how do I get the data fields (u7 + ", " + tag;) & (tag + ", " + fn;) to appear on separate lines, I was looking at  Concatenating the fields with each field on its own line (as seen in the forum) and I was wondering, am I on the right path with this?

    I tried putting them together but failed, unfortunately the last time I did C++ (C# in this case) was more than a decade ago!

    private void xrTableCell18_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
    	string pn = "", u7 = "", tag = "", fn = "" ;
    	if (GetCurrentColumnValue("partnumber") != DBNull.Value)
    		pn = (string)GetCurrentColumnValue("partnumber");
    	if (GetCurrentColumnValue("user7") != DBNull.Value)
    		u7 = (string)GetCurrentColumnValue("user7");
    	if (GetCurrentColumnValue("DeviceTag") != DBNull.Value)
    		tag = (string)GetCurrentColumnValue("DeviceTag");	
    	if (GetCurrentColumnValue("functiontext") != DBNull.Value)
    		fn = (string)GetCurrentColumnValue("functiontext");
    	
    	if (pn == "XA4349")
    		(sender as XRLabel).Text = u7 + ", " + tag;
    		
    	else
    		(sender as XRLabel).Text = tag + ", " + fn;
    
    }
    

  • I had an issue whereby I tried to run the report on a current project and it simply wouldn't populate the data fields, which made me think the script wasn't working, so then I decided to create a new project from scratch and then placed down a few symbols with a couple of different part numbers and the script and report ran perfectly?

    My first guesses is that you need to use Show Differences in the first project, or there is a Filter applied to the template (check the Filters button on Run Reports) and nothing in the first project matches the filter.

    I'm just wondering how do I get the data fields (u7 + ", " + tag;) & (tag + ", " + fn;) to appear on separate lines

    I'm not sure what you mean by this. Currently you're showing either in one cell. Do you want to show both in the same cell? Or you want to show each in their own cell? Maybe a screen shot would help.



  • I'm getting the required output its just I need to show them on separate lines.

    Current output

    The material list needs to be output as shown below, basically u7 and tag need to be output on separate lines and the same for tag and fn

  • Try this:

    (sender as XRLabel).Text = tag + Environment.NewLine + fn;

    You will have to set the Multiline property for the cell/label to "Yes" for this to work. The Multiline property is in the Behavior category.

    See also the Concatenating fields on report templates article.



    Answer Verified By: Toby77