Use column formatting to customize SharePoint - sharepoint

I'm following this article:
https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#formatting-items-based-on-arbitrary-dates-advanced
I have an SP List with Renewal Date and would like to be it marked if the date is smaller than today-31 days so I modified the example from the article to:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField",
"style": {
"color": "=if([$Renewal_x0020_Date] <= #now - 2678400000‬, '#ff0000', '')"
}
}
So, according to "to add a day to a date, you'd add (24*60*60*1000 = 86,400,000)" I multiply this by 31.
Unfortunately, the JSON doesn't format my view.
Could someone direct me, please?
Thanks
Slawek

Column formatting seems to be working for modern experience only. Here are the results.
New/Modern Experience
Classic Experience:
So Try switching the experience if your list is currently set to open in classic view.

First example with $RenewalDate
Try with this ternary (?) operator code
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField",
"style": {
"color": {
"operator": "?",
"operands": [
{
"operator": "<=",
"operands": [
"[$RenewalDate]",
{
"operator": "+",
"operands": [
"#now",
-2678400000
]
}
]
},
"#ff0000",
""
]
}
}
}
Second example is column with space in name $Renewal_x0020_Date
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField",
"style": {
"color": {
"operator": "?",
"operands": [
{
"operator": "<=",
"operands": [
"[$Renewal_x0020_Date]",
{
"operator": "+",
"operands": [
"#now",
-2678400000
]
}
]
},
"#ff0000",
""
]
}
}
}
EDIT:
using the Excel-style expression syntax
Column without space $RenewalDate
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField",
"style": {
"color": "=if([$RenewalDate] <= #now - 2678400000, '#ff0000', '')"
}
}
Column with space $Renewal_x0020_Date
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField",
"style": {
"color": "=if([$Renewal_x0020_Date] <= #now - 2678400000, '#ff0000', '')"
}
}

Related

Filter by Product Properties with Store API

For the store API endpoint /store-api/product is it possible to filter on the properties of a product? Not the defaults such as whether it's active or stock levels, but the properties we've defined on the product, for example colour or farbe? For the search endpoint it supports passing in a list of properties ID's which this one does not.
None of the below queries work, and return the various errors below or Call to a member function buildAccessor() on null.
{
"limit": 40,
"filter": [
{
"type": "contains",
"field": "Farbe",
"value": "red"
}
]
}
"Field \"Farbe\" in entity \"product\" was not found."
{
"limit": 40,
"filter": [
{
"type": "contains",
"field": "properties.Farbe",
"value": "red"
}
]
}
"Field \"Farbe\" in entity \"property_group_option\" was not found."
You can combine filters for the name of the property value and their respective group in a multi filter. The following example will only give you products that have the "shoe-color" property with the value "coral".
{
"limit": 1,
"includes": {
"product": ["id", "productNumber", "properties"],
"property_group_option": ["name", "group"],
"property_group": ["name"]
},
"associations": {
"properties": {
"associations": {
"group": []
}
}
},
"filter": [
{
"type": "multi",
"operator": "and",
"queries": [
{
"type": "equals",
"field": "properties.group.name",
"value": "shoe-color"
},
{
"type": "equals",
"field": "properties.name",
"value": "coral"
}
]
}
]
}
Example response:
{
"entity": "product",
"total": 1,
"aggregations": [],
"page": 1,
"limit": 1,
"elements": [
{
"productNumber": "6bbfe1f608504c9b9a7bf92d6a071734",
"properties": [
{
"name": "coral",
"group": {
"name": "shoe-color",
"apiAlias": "property_group"
},
"apiAlias": "property_group_option"
},
{
"name": "cotton",
"group": {
"name": "textile",
"apiAlias": "property_group"
},
"apiAlias": "property_group_option"
}
],
"id": "062ba988aa1840fa84371c9c43b2f838",
"apiAlias": "product"
}
],
"states": [],
"apiAlias": "dal_entity_search_result"
}

Azure Resource Manager Query with multiple dynamic tag filters

I'm trying to query the Azure Cost Management API and I want to be able to filter the results based off of 2 different types of resource tags but I am having trouble figuring out the format. I can get the single tag filter working, but I'm blanking on the format for multiple. Can anyone throw in their 2 cents?
Working single filter query:
{
"type": "Usage",
"timeframe": "{TimeFrame}",
"dataset": {
"granularity": "None",
"filter": {
"tags": {
"name": "Environment",
"operator": "In",
"values": [
{Environment}
]
}
},
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "{Aggregation}"
}
]
}
}
My attempt at adding more than one filter:
{
"type": "Usage",
"timeframe": "{TimeFrame}",
"dataset": {
"granularity": "None",
"filter": {
"tags": [
{
"name": "Environment",
"operator": "In",
"values": [
{Environment}
]
},
{
"name": "Location",
"operator": "In",
"values": [
{Location}
]
}
]
},
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "{Aggregation}"
}
]
}
}
I am very new to Azure so please don't roast me too hard lol.
Thank you to everyone who took a look at my question, much appreciated even if you don't have an answer for me.
There was an issue with the way my parameters were set causing a bad query. Here is the working code with multiple tag attributes for filtering:
{
"type": "Usage",
"timeframe": "{TimeFrame}",
"dataset": {
"granularity": "None",
"filter": {
"and": [
{
"tags": {
"name": "Location",
"operator": "In",
"values": [{LocationTag}]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"Values": [{EnvironmentTag}]
}
},
{
"tags": {
"name": "Integrated-System",
"operator": "In",
"Values": [{IntegratedSystemTag}]
}
}
]
},
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "{Aggregation}"
}
]
}
}

MS Lists Lookup column not found in data object

I have two lists A and B. I've created a lookup column on B to get data from A (item # and item address). I want to customize the view when opening an item on list B. But I can't find a way to make the fields from A visible on B. I get
Failure: TEST_x0020_SHIPPING_x0020_ADDRES1 was not found on the data object.
I checked the name of the field and it's correct and contains data. Please check the attached image. Is there a way to get that information on that view?
Note: if I disable debug it shows nothing.
Thanks in advance!
JSONERROR
Update: The code I'm using on the Header comes from the MS official site https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/list-form-configuration
{
"debugMode": false,
"elmType": "div",
"attributes": {
"class": "ms-borderColor-neutralTertiary"
},
"style": {
"width": "99%",
"border-top-width": "0px",
"border-bottom-width": "1px",
"border-left-width": "0px",
"border-right-width": "0px",
"border-style": "solid",
"margin-bottom": "16px"
},
"children": [
{
"elmType": "div",
"style": {
"display": "flex",
"box-sizing": "border-box",
"align-items": "center"
},
"children": [
{
"elmType": "div",
"attributes": {
"iconName": "Devices3",
"class": "ms-fontSize-42 ms-fontWeight-regular ms-fontColor-themePrimary",
"title": "Details"
},
"style": {
"flex": "none",
"padding": "0px",
"padding-left": "0px",
"height": "36px"
}
}
]
},
{
"elmType": "div",
"attributes": {
"class": "ms-fontColor-neutralSecondary ms-fontWeight-bold ms-fontSize-24"
},
"style": {
"box-sizing": "border-box",
"width": "100%",
"text-align": "left",
"padding": "21px 12px",
"overflow": "hidden"
},
"children": [
{
"elmType": "div",
"txtContent": "='Store ' + [$TEST_x0020_SHIPPING_x0020_ADDRES1]"
}
]
}
]
}

Button in Sharepoint list - conditional visibility

I'm trying to create a button that only appears if the "Zapůjčeno" column is empty.
{
"elmType": "button",
"txtContent": "Odeslat Žádost",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\": \"7347b7be-696f-46c8-bae8-78c230a354b3\"}"
},
"style": {
"background-color": "#03A9F4",
"color": "white",
"visibility": {
"operator": "?",
"operands": [
{
"operator": "!=",
"operands": [
"[$ID]",
"1"
]
},
"hidden",
"visible"
]
}
}
}
Example with "ID" column
If I try it with the default column "ID" it works, but if I want to use my column "Zapůjčeno" it doesn't work.
Thank you for your advice, I am a novice in SharePoint.
Is the column Zapůjčeno internal name the same as the display name? You can see the internal name of that column in list/library settings an then click on the column name. The internal name of this column will in the URL.
I think you can then use something like this:
{
"elmType": "button",
"txtContent": "= if([$Zapůjčeno_Internal_Name]=='','Odeslat Žádost', '')",
"customRowAction": {
"action": "executeFlow",
"actionParams": "='{\"id\": \"' + if([$Zapůjčeno_Internal_Name]=='','7347b7be-696f-46c8-bae8-78c230a354b3','') + '\"}'"
},
"style": {
"background-color": "#03A9F4",
"color": "white",
"visibility": {
"operator": "?",
"operands": [
{
"operator": "!=",
"operands": [
"[$ID]",
"1"
]
},
"hidden",
"visible"
]
}
}
}
As #Rikking said, you need ro use the internal name in json.
My test column formating json for your reference:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"children":[
{
"elmType":"button",
"style":{
"background-color":"=if([$Zap_x016f_j_x010d_eno]=='','lightblue','')",
"width":"80px",
"height":"50px",
"display":"=if([$Zap_x016f_j_x010d_eno]=='','','none')"
},
"txtContent":"=if([$Zap_x016f_j_x010d_eno]=='','Odeslat Žádost','')"
}
]
}
Test result:
Zap_x016f_j_x010d_eno is the internal name of Zapůjčeno,the default language of my SharePoint Online is English.

Query to search for values ​inside an array object

I have this object in my mongo. Inside the "conditions.all" array there is a list of objects with the fields fact, operator and value. I need a query to find the document in which the year value inside the object that has fact: "year", for example, in this case, the value 1970, compare whether this value is greater or less than an input value
{
"_id": { "$oid": "5fc14323bd1f87002e8ca7ac" },
"priority": { "$numberInt": "6" },
"type": "pricing",
"name": "BLOCK AUDI A6",
"conditions": {
"all": [
{ "fact": "brand", "operator": "equal", "value": "AUDI" },
{ "fact": "model", "operator": "equal", "value": "A6" },
{
"fact": "version",
"operator": "in",
"value": [
"3.0 TFSI QUATTRO V6 24V GASOLINA 4P TIPTRONIC",
"2.0 TFSI AMBIENTE GASOLINA 4P S-TRONIC",
"3.0 TFSI ALLROAD 24V GASOLINA 4P S-TRONIC",
"3.0 TFSI QUATTRO V6 24V GASOLINA 4P S-TRONIC"
]
},
{
"fact": "km",
"operator": "greaterThanInclusive",
"value": { "$numberInt": "0" }
},
{
"fact": "km",
"operator": "lessThanInclusive",
"value": { "$numberInt": "1000000" }
},
{
"fact": "year",
"operator": "greaterThanInclusive",
"value": { "$numberInt": "1970" }
}
]
},...
I am currently using a query that checks the value inside the entire array, like this:
this.getCollection().aggregate({ $match: {"conditions.all.value":{$lte:2050} } })
but now i need to check the value inside the object specified by the fact field
I think this query can be helpful for this question:-
this.getCollection().aggregate({$match:{$and:[{"conditions.all.fact":"year"}, {"condition.all.value":{$or:[{$lte:1970},{$gte:1970}]}}]}})

Resources