How to get current detail record number in field class in Connect Designer

Hello,

Could you please tell me how to get the current detail record number within a field class in Connect Designer?

Here’s the code of the class:

///// begin
var field;

field = record.tables.detail[0].fields.Field_InventPickingListTrans_SalesQty;

if (field > 1.00)
{
results.css(“background-color”,“#c0c0c0”);
results.css(“border”,“1px solid black”);
}
///// end

The code above works well for the input detail record number.

I’m guessing there must be some special value for the current detail record number, like record.tables.detail[currentRec], or something similar?

Here’s the Preview view of my template, with QTY corresponding to Field_InventPickingListTrans_SalesQty in the code above:

image

Thanks,

Brian

Hi Brian,

Which version of Connect are you using? To be more precise do you know if your table is created with the latest dynamic table implementation? This can be viewed in the source of the section, the table in that case will have the data-expander=“2019” attribute.

Erik

Yes, the table is created with the latest dynamic table implementation: data-expander=“2019”

Here’s a screenshot of the Edit Script dialog if that provides any more information:

Thanks!

I suggest to change the scope of the script. To do this: open the Options section at the bottom of the Edit Script dialog and change the scope to Each matched element. This exposes the “this” object for your script which provides access to the record used to generate this dynamic row.

The following script iterates over the table cells with .SalesQty class. The script evaluates the data used for this field and sets the background color of the cell when the value is larger than 2.

Selector: .SalesQty

var qty = this.record.fields.Quantity;

if ( qty > 2 ) {
	this.css('background-color','#c0c0c0');
}

Hope this helps,

Erik

I changed the scope to Each matched element and modified the code to the following and it worked:

var field;

field = this.record.fields.Field_InventPickingListTrans_SalesQty;

if (field > 1.00)
{
this.css(“background-color”,“#c0c0c0”);
this.css(“border”,“1px solid black”);
}

image

Thank you very much! :slight_smile:

Glad it helped.

Erik