Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON “@currentField.lookupValue” throws error in case of blank lookup value #36

Closed
Kirill-FP opened this issue Mar 21, 2018 · 10 comments

Comments

@Kirill-FP
Copy link

https://stackoverflow.com/questions/49392815/sharepoint-column-formatting-json-currentfield-lookupvalue-throws-error-in-c

I've got a SharePoint List with the column "Status - Overall (lookup)" which type is "Lookup". It gets information from another list and there can be only 5 values: "Red", "Amber", "Green", "Gray" or blank value.

I applied conditional column formatting to the column "Status - Overall (lookup)" according to the article: https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

Here's JSON code which was pasted into "Column Formatting" setting of the List Column:

{
"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"debugMode": true,
"elmType": "div",
"attributes": {
"class": {
"operator": "?",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toString()",
"operands": [
"@currentField.lookupValue"
]
},
"Green"
]
},
"sp-field-severity--good",
{
"operator": "?",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toString()",
"operands": [
"@currentField.lookupValue"
]
},
"Gray" ]
},
"sp-field-severity--low",
{
"operator": "?",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toString()",
"operands": [
"@currentField.lookupValue"
]
},
"Amber"
]
},
"sp-field-severity--warning",
{
"operator": "?",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toString()",
"operands": [
"@currentField.lookupValue"
]
},
"Red"
]
},
"sp-field-severity--severeWarning",
"sp-field-severity--blocked"
]
}
]
}
]
}
]
}
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block",
"padding": "0 4px"
},
"attributes": {
"iconName": {
"operator": "?",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toString()",
"operands": [
"@currentField.lookupValue"
]
},
"Green"
]
},
"CheckMark",
{
"operator": "?",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toString()",
"operands": [
"@currentField.lookupValue"
]
},
"Amber"
]
},
"Forward",
{
"operator": "?",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toString()",
"operands": [
"@currentField.lookupValue"
]
},
"Gray"
]
},
"Error",
{
"operator": "?",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toString()",
"operands": [
"@currentField.lookupValue"
]
},
"Red"
]
},
"Warning",
"ErrorBadge"
]
}
]
}
]
}
]
}
}
},
{
"elmType": "span",
"txtContent": "@currentField.lookupValue"
}
]}

This JSON works fine for all lookup values except the blank value which displays the following error:

(column-internal-name).lookupValue was not found on the data object.

https://i.stack.imgur.com/OJ7TW.jpg

Is there a way to fix that?

@thechriskent
Copy link
Contributor

Turn debugMode off to suppress this error:

"debugMode": false

@Kirill-FP
Copy link
Author

Thanks. This works!

@ErikSavetheCrew
Copy link

ErikSavetheCrew commented Nov 6, 2018

I'm having the same type of issue, but with a lookup field and a person field - when the fields are blank, the records aren't returned in the (formatted) view at all. I noticed the error when I had a simple text element:

{
    "elmType": "span",
    "txtContent": "[$TeamCategoryLookup.lookupValue]"
}

I've tried all kinds of options - including turning debug mode off and using a lot of conditional statements to set it to a blank value if it's empty. Unfortunately nothing I've tried works, including the following:

"txtContent": "= if(ToString([$TeamCategoryLookup.lookupValue])=='', '',[$TeamCategoryLookup.lookupValue])"
"txtContent": "= if(ToString([$TeamCategoryLookup])=='', '',[$TeamCategoryLookup.lookupValue])"

"txtContent": "= if(isEmpty([$TeamCategoryLookup.lookupValue]), '',[$TeamCategoryLookup.lookupValue])"
"txtContent": "= if(isEmpty([$TeamCategoryLookup]), '',[$TeamCategoryLookup.lookupValue])"

"txtContent": "= if(isNull([$TeamCategoryLookup.lookupValue]), '',[$TeamCategoryLookup.lookupValue])"
"txtContent": "= if(isNull([$TeamCategoryLookup]), '',[$TeamCategoryLookup.lookupValue])"

"txtContent": "= if(isBlank([$TeamCategoryLookup.lookupValue]), '',[$TeamCategoryLookup.lookupValue])"
"txtContent": "= if(isBlank([$TeamCategoryLookup]), '',[$TeamCategoryLookup.lookupValue])"

"txtContent": "= if(isBlank(ToString([$TeamCategoryLookup.lookupValue])), '',[$TeamCategoryLookup.lookupValue])"
"txtContent": "= if(isBlank(ToString([$TeamCategoryLookup])), '',[$TeamCategoryLookup.lookupValue])"

Any ideas? (as a side note, should I be using the operator style instead of ifs?)

@PopWarner
Copy link
Contributor

Quick question for you @ErikSavetheCrew, is your lookup field pointing a person field? Wanted to confirm before I did some testing for ya. :)

@ErikSavetheCrew
Copy link

@PopWarner It's not, it's just pointing at some text values in another list. I mentioned the people field because I think I'm having the same issue with a people field (it's hard to say for certain, but it might make sense because they're both objects).

I've attached the full code if it's helpful (the problem fields are [$T1Assignee] and [$TeamCategoryLookup]). It's a little buggy pulling records in general right now (it won't show certain records until filters are selected on the list, and some things don't appear at all), but after reviewing what's in the records, I think it's this object issue that's at the root of it.

Appreciate any ideas you come up with!

TileImproved6.txt

@PopWarner
Copy link
Contributor

@ErikSavetheCrew Great...Thank you. I'll try to take a look in my tenant and see what I see as well. :)

@PopWarner
Copy link
Contributor

@ErikSavetheCrew, quick question, when you say "when the fields are blank", do you mean the lookup field in the lookup list is blank or do you mean the list that your applying the ViewFormatting to has a list item, where you have not selected anything from the lookup field?

I'm trying to mimic the scenario, wanted to make sure I'm testing exactly as you are.. :)

@ErikSavetheCrew
Copy link

ErikSavetheCrew commented Nov 7, 2018 via email

@PopWarner
Copy link
Contributor

@ErikSavetheCrew Thanks!!!

So I started with a VERY simple couple of list items and lists. I've attached my LF JSON.

In the picture, it seemed to work for me. The first list item is one where I provided a title AND selected from the lookup. The second is where I provided a title, but NOT a lookup choice. They both seem to show up for me using the attached JSON.

Curious if the attached JSON works for you? My thought is if so, perhaps something else is going on with the larger JSON you attached earlier. I'm happy to keep helping troubleshoot, but figured I'd check with ya and see if this works first? :)

image

ErikSavetheCrewSample.txt

@ErikSavetheCrew
Copy link

ErikSavetheCrew commented Nov 7, 2018

Thanks @PopWarner. I'll create another list in a bit to test it out there. To your point about the larger JSON file, this is actually part of a bigger problem, which I was going to post elsewhere (and still can if it makes sense, it's a long, stupid story):

I created a heavily-modified card view based on these tiles as a starting point. The view it's applied to shows every entry in a certain list, and when viewing without any formatting all 277 rows load appropriately (in batches of 50 as specified in the view).

The issue is, when loading the view with formatting on, all the cards will flash on the screen briefly, but then the majority will disappear (except for 3, which I'll called "Green"). I attached a .gif that shows what I mean. Depending on what filters are applied to the view, different amounts of cards will load, so it's not an item limit, and I've had the behavior appear in both Firefox and Chrome. The odd thing about it is that certain cards won't show up initially, but if I open up the sidebar and filter (or use the view filters), more cards will show up after filtering (I'll call those "Yellow").

So I combed through the records to see if it's a particular field that's causing the odd behavior, which is how I ended up here. I realized that records without a value in one of these two fields ([$T1Assignee] and ([$TeamCategoryLookup]) never showed up, no matter how many filters I applied (I'll call these "orange"). Looking even further (and this is kind of hard to word, my apologies), when the view is filtered so that none of these "orange" problematic records are in the subset, every (green and yellow) record loads correctly. So it seems like not only do these problematic records not display, but they keep other (yellow) records from displaying as well.

It's also possible it's something else entirely! Today I've been combing through some more, and when I removed both fields it got glitchy for a second, and then showed the original 3 "green" ones plus some random "orange" ones, and the same behavior while filtering. I about lost my lid. Not sure where I'm going wrong.
loadingerror2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants