Display Rules Using Values from Connected Object's Field

Trying to show the values of a field based on the value of a connected object’s field.

Knack allows you to place the connected field on the details page, but doesn’t allow you to reference the field in “display rules”. Basically I want to show a field value for a field if connected object/field value is “NO”

I’ve been using OpenAI to assist with scripts and it does a pretty code job for me, however I can’t figure out the below code. Connected field is located in Table “Accounts” and is “field 380”. Field I want to show or hide based on connected field 380’s value is field_144 on view_287. Any and all help is appreciated… JON

HERE’S OPENAI’S CODE:

// Wait for the page to finish loading
document.addEventListener(“DOMContentLoaded”, function() {

// Get the connection field element within the view_287 container
var connectionField = document.querySelector(“#view_287 [data-field-key=‘field_380’]”);

// Get the field element you want to show
var fieldToShow = document.getElementById(“.field_144”);

// Show the field if the connection field value is “NO”
if (connectionField && connectionField.textContent.trim() === “NO”) {
fieldToShow.style.display = “block”;
} else {
fieldToShow.style.display = “none”;
}
});

Hi Jon,

I am working on this feature right now in the KTL.

The new keyword (to be determined) will be able to compare any fields’ values in a page, and take action upon the result: show, hide, or any others as requested.

If you have ideas, it’s time to feed me!

Norm

Sounds GREAT!!! I’m trying to get away from using “tasks” in Knack, it’s super slow and very unreliable and by having this feature should help greatly.

Hey Norm, just checking in to see how the feature of comparing any fields values in a page for KTL is coming. ???

JON

Jon,

I’ve just completed the KTL feature that does what you want - and a lot more!
I will do the official release tomorrow morning.

Stay tuned,
Norm

Sounds good. Look forward to seeing this new feature…

The release is done: v0.13.15.

It allows hiding a field based on another field’s value.

In your details view’s description, add this:

_cfv=[field_380, eq, No, , , ,rp], [ktlTarget, field_144]

It means:

Compare field_380 and if Not Equal to No, remove text and field (p for propagate) for field_144 in same view.

Note that the _cfv feature can also find the field and view IDs automatically. You can type the field’s label or view’s title. It is more intuitive that having to find the field_id and view_id.

Documentation can be found here:
Colorize Field by Value - Wiki

Let me know if it works,
Norm

Hey Norm, been trying you new feature and got some questions:

  1. Is there a way to hide an action link on the details page based on a connected field value? Example: field_380 = “YES” then hide action link.

  2. Is there a way to hide the field you are referencing? To make your new feature work, you must show the field on the details page. I tried to hide the label and just show the field value but it appears you must show both the label and the field value. Is there a way around this and hide both the label and field value?

  3. Using your example, _cfv=[field_380, eq, No, , , ,rp], [ktlTarget, field_144], if I wanted multiple fields to hide, how would I do this. For example hide “field_144” and “field_145” if field_380 = “NO”.

Thanks again for all that you do… JON

Hi @Jon1!

Thank you for sharing your question, and I’m sorry you haven’t had a great experience with Tasks so far. I wanted to ask if you have reported any of your tasks working slowly or reported the unreliability of them with our support team?

We would love to take a look into a recent task that hasn’t performed as expected and see what we can do to help. Also, the more these issues get reported, the more information we have to work with to improve the performance of tasks in general.

If you haven’t reached out already, you can reach out to our support team directly in your app, or submit this form here: Form.

Happy Knacking!

Les, I have reported task issues multiple times including, at her request, directly to Kara about these issues.

1 Like

Jon,

Yes, all that you’re asking is possible,but not fully supported yet.
I am working on this right now.

Will keep you posted in a few hours, if all goes as planned.

Norm

Sounds good… BTW, this new KTL feature looks like it is going to help me get around using the built in task feature that Knack provides.

I’ve had nothing but issues with their feature and hoping with your help, myself and others that are having issues with Knack’s task feature will benefit from your hard work.

Greatly appreciate you and KTL… JON

1 Like

Jon,

Can you try adding these two keywords is in your details view’s description please?

_cfv=[field_380, eq, No, , , ,hp], [ktlTarget, #view_287 .kn-details-link:contains(“My Action”), .kn-detail:contains(“My Field1”), .kn-detail:contains(“My Field2”)]
_hf=field_id

Replace the text in bold by yours. Use the field names exactly as they are written - not their IDs.

_hf is to Hide Fields. Currently, it only supports the field_id, but will support both the ID of the name in next release. You can have many fields, separated by commas.

What you see there in the ktlTarget group leverages the new Universal Selector concept in KTL. Whenever you can’t use the field IDs and view IDs (or their names) to achieve your goal, then you can recourse to the powerful jQuery selector. It involves a bit more complexity, and may be difficult to understand for newbies, but it can select almost anything. Well worth the learning curve.

Let me know if it works,
Norm

Norm, tried new code but couldn’t get it to work.

I added a new “edit” action link to details view and labeled it “TEST” but no matter what I did, couldn’t hide it.

Also, I had the keyword _hf working but it stopped working just right before this post.

Can you give me access to that page, with any data?
I will not change anything. Just see what you have in there to determine the jQuery string you need.

Use my nd@ctrnd.com email and send me a PW in private message.

Norm

Thank you for taking the time to do that. We are working on improving our jobs system (which would include task performance), so your reports of these issues definitely helps us out!

Jon,

I’ve just release a beta version of KTL v0.14.0.
Can you set your app to this in the loader and test again please?

This time, let’s go back to basics, and forget the jQuery selector.

The _cfv keyword now supports multiple targets, including Action links.

So you would use something like this string:

_cfv=[field_380, eq, NO, , , ,hp], [ktlTarget, field_144, field_145]

But use the field and view names instead of their IDs.
Remember that the text must be exactly the same - case sensitive.

I updated the No to NO to match your example. Maybe that’s why it didn’t work. Sorry if that’s the case.

Let me know how it goes. We’ll make this work… I promise.

Norm

Hey Norm, thanks again for doing this…

I can get one field to hide but when I try multiple fields in the string, neither field will hide.

Example:

_cfv=[field_380, eq, NO, , , ,hp], [ktlTarget, TEST1] hides field named “TEST1”

_cfv=[field_380, eq, NO, , , ,hp], [ktlTarget, TEST2] hides field named “TEST2”

_cfv=[field_380, eq, NO, , , ,hp], [ktlTarget, TEST1, TEST2] hides neither field

The keyword “_hf” is working now as long as I don’t use field ID and use the actual name of field on screen.

As for hiding the action links, I created (3) sample action links named “edit”, “delete” and “testlink”. I tried each one of them in the string and no matter what I did, can’t seem to get the action links to hide.

Example: _cfv=[field_380, eq, NO, , , ,hp], [ktlTarget, edit] doesn’t hide the action link named “edit”

I caught the case sensitive “No” yesterday and corrected it to “NO”

Question for you, is there a way to “show” a field based on field value?

For example: if field_380 is “YES” then show field_100’s value?

Thanks again Norm… JON

Good morning Jon!

The problems you’re having are very strange. I try all you say and here, all works well.
Are you sure you are at 0.14.0 ?

We should have a Zoom or Teams meeting (or other SW). Otherwise, we’ll waste to much time writing back and forth.

Are you available now?

Norm

This works well here in both cases. We need to investigate.

You’re right on this one. I’ve just fixed it. Press Ctrl+F5 for a full refresh of your cache to test it. Since the version hasn’t changed, if you don’t do that, you will not see the changes.

ND