XRM-OSS / Xrm-Templating-Language

A domain specific language for Dynamics CRM allowing for easy text template processing
https://xrmadventuretime.com/tag/xtl/
MIT License
22 stars 8 forks source link

Conditionally show/hide column value in RecordTable #46

Open alexmare93 opened 2 years ago

alexmare93 commented 2 years ago

Hi @DigitalFlow,

How can I show/hide a column inside RecordTable based a value of that same fetchXml result? I put an example:

I have a fetchXml which results 3 records. I have a RecordTable column called "Importo imponibile storno" that, if the field sap_transferline is set = Yes, I have to show the value of field sap_amount, else if field sap_transferline is set = No, always in the column "Importo imponibile storno" I have to show the value of field sap_deltaamount. I need that the column keeps having its label name. This is currently my recordtable:

${{RecordTable ( Fetch ( "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='sap_creditnoteproposaldetail'><attribute name='sap_creditnoteproposaldetailid'/><attribute name='sap_productdescription'/><attribute name='sap_invoicenumber'/><attribute name='sap_invoicedate'/><attribute name='sap_amount'/><attribute name='sap_deltaamount'/><attribute name='sap_transferline'/><attribute name='ownerid'/><order attribute='sap_name' descending='false'/><filter type='and'><condition attribute='sap_creditnoteproposalid' operator='eq' value='{1}'/></filter></entity></fetch>", Array(Value("regardingobjectid.sap_creditnoteproposalid"))), "sap_creditnoteproposal", [{ name: "sap_invoicenumber", label: "N. Fattura"}, { name: "sap_invoicedate", label: "Data Fattura", renderFunction: (record, column) => DateToString(Value(column, { explicitTarget: record }), { format: "dd/MM/yyyy" }) },{ name: "sap_productdesc", label: "Descrizione Prodotto"},{ name: "sap_amount", label: "Importo imponibile storno", renderFunction: (record, column) => Format(Value(column, {explicitTarget: record}), {format: "{0:0.00}"})}], true)}}

How could I resolve that?

Thank you, Regards

alexmare93 commented 2 years ago

Hi @DigitalFlow ,

Could you please give me some advice?

Thank you, Regards

DigitalFlow commented 2 years ago

Hi @alexmare93,

That should be doable with a renderFunction which contains an if and checks for your column to modify the output. You can write arbitrary XTL code inside the renderFunctions :)

Should look something like this:

${{RecordTable ( Fetch ( "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='sap_creditnoteproposaldetail'><attribute name='sap_creditnoteproposaldetailid'/><attribute name='sap_productdescription'/><attribute name='sap_invoicenumber'/><attribute name='sap_invoicedate'/><attribute name='sap_amount'/><attribute name='sap_deltaamount'/><attribute name='sap_transferline'/><attribute name='ownerid'/><order attribute='sap_name' descending='false'/><filter type='and'><condition attribute='sap_creditnoteproposalid' operator='eq' value='{1}'/></filter></entity></fetch>", Array(Value("regardingobjectid.sap_creditnoteproposalid"))), "sap_creditnoteproposal", [{ name: "sap_invoicenumber", label: "N. Fattura"}, { name: "sap_invoicedate", label: "Data Fattura", renderFunction: (record, column) => DateToString(Value(column, { explicitTarget: record }), { format: "dd/MM/yyyy" }) },{ name: "sap_productdesc", label: "Descrizione Prodotto"},{ name: "sap_amount", label: "Importo imponibile storno", renderFunction: (record, column) => If(IsEqual(Value("sap_transferline", { explicitTarget: record }), true), Format(Value(column, {explicitTarget: record}), {format: "{0:0.00}"}), Format(Value("sap_deltaamount", {explicitTarget: record}), {format: "{0:0.00}"}))}], true)}}

Hope that helps.

Kind regards, Florian

DigitalFlow commented 2 years ago

Hi @alexmare93,

any news? I hope that my snippet should be able to solve your problem.

Kind regards, Florian

alexmare93 commented 2 years ago

Hi @DigitalFlow ,

I'm sorry but I was on vacation. I will try what you suggest and I'll let you know. Thank you very much,

Regards, Alessandro

Cris682 commented 2 years ago

Hi @DigitalFlow , I'm a colleague of Alexmare93, we work on the same project. Unfortunately the example provided does not work, the condition remains false even when the field is Y. The sap_transferline field is an OptionSet with 3 possible values, and respective 9-digit keys. I tried to pass the value "Y" once and then the key "804.060.000" but the condition always remains false. Surely I am wrong something in the condition on OptionSet. I tried searching the documentation but couldn't find any explanation for this specific case. Could you kindly help me?

Regards, Cris.

alexmare93 commented 2 years ago

Hi @DigitalFlow ,

It seems we found the solution:

From this:

immagine

To this:

immagine

The missing part was the explicitTarget specified for the field/column. We're going to make further test and, if everything is ok, we can close the thread.

Thank you, Regards Alessandro

DigitalFlow commented 2 years ago

Hi Alessandro,

glad to hear that you found the cause :)

Yes sure, I'll await your test results.

Kind regards, Florian