Adding Search option For reference a attribute
Question

I'm working on a Search feature currently and I had a search option set up for the Project ID and Project Name and it works fine. But I had to add an option to search by Project Lead which is a reference attribute in my Entity. So when I try to set it up in a same way as Project ID and Name I got a type incompatibility error. Does anyone know of a way to overcome this problem?

 I tried using a different Client variable that had user identifier as data type so it would match, but it still threw the same error. So I assume the problem lies with Project.ProjectLead, but I can't change the data type for it.


Hi Kristina,

It also depends on what you want to search your person on.

We don't see your datamodel, but what is common is that you have some entity with the id and things like the name of that person, and in your project entity you have a reference attribute of type {whateverTableYourProjectLeadsAreIn}.[Id].  For example user.id, but it could be something else...

When you want your users to search on project lead, you probably don't want to have the identifier as a search string, but the name of that project lead.  In order to do that, you'll have to expand your aggregate, adding the table that you store your project leads in (the table the project entity references to) as a second source, using a join condition something like project.projectleadid = projectlead.id.

Once you've done that, you can have your condition like

Project.Name like "%" + SearchString + "%"

or Project.ProjectId like "%" + SearchString + "%"

or ProjectLead.FirstName like  "%" + SearchString + "%"

or ProjectLead.LastName like  "%" + SearchString + "%"

Hope you understand, we don't see your datamodel, so we don't know what exactly this will look like.  The above isn't perfect though, when the user searches by typing both the first and lastname, it won't work.


The error you are getting in that screenprint, is about using a like operator on a numeric field.  If you would really want your users to search on that persons id (which I don't think, i imagine you want to allow them to search on that persons name), then you could use an = operator instead of a like, forcing them to know the whole id, or you could compare the searchfield with IdentifierToText(Person.Id) as Jose is suggesting.

Dorine

Following the answer of @Dorine Boudry I actually simply used the entity that is referenced in the ProjectLead attribute and added it to the Search "statement" instead of using ProjectLead attribute itself. This seemed to do the trick and it's working now. Thank you for everyone's help.

Hi Kristina,

convert the ProjectLead to Text in the Expression Editor:

"IdentifierToText(Project.ProjectLead)"

mvp_badge
MVP

Hi Kristina,

What's the data type for "Project.ProjectLead"? Is it Text (or a Text Identifier)?

Hi Kristina,

It also depends on what you want to search your person on.

We don't see your datamodel, but what is common is that you have some entity with the id and things like the name of that person, and in your project entity you have a reference attribute of type {whateverTableYourProjectLeadsAreIn}.[Id].  For example user.id, but it could be something else...

When you want your users to search on project lead, you probably don't want to have the identifier as a search string, but the name of that project lead.  In order to do that, you'll have to expand your aggregate, adding the table that you store your project leads in (the table the project entity references to) as a second source, using a join condition something like project.projectleadid = projectlead.id.

Once you've done that, you can have your condition like

Project.Name like "%" + SearchString + "%"

or Project.ProjectId like "%" + SearchString + "%"

or ProjectLead.FirstName like  "%" + SearchString + "%"

or ProjectLead.LastName like  "%" + SearchString + "%"

Hope you understand, we don't see your datamodel, so we don't know what exactly this will look like.  The above isn't perfect though, when the user searches by typing both the first and lastname, it won't work.


The error you are getting in that screenprint, is about using a like operator on a numeric field.  If you would really want your users to search on that persons id (which I don't think, i imagine you want to allow them to search on that persons name), then you could use an = operator instead of a like, forcing them to know the whole id, or you could compare the searchfield with IdentifierToText(Person.Id) as Jose is suggesting.

Dorine

Following the answer of @Dorine Boudry I actually simply used the entity that is referenced in the ProjectLead attribute and added it to the Search "statement" instead of using ProjectLead attribute itself. This seemed to do the trick and it's working now. Thank you for everyone's help.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.