0

I have a very tough situation here. Let's start with a screen shot:

enter image description here

So as you can see, some of the entries have several dashes (which the client had done manually) to give the appearance of indented child entries. An example:

enter image description here

As you can see "SD 100 Smithsonian Directives ought to be the "parent", while the other 3 beneath is should be the child tasks. It was suggested to me to utilize JSON to indent these child tasks, but I don't see how that would be beneficial. An alternative I considered would be to simply remove the dashes in front of entries like "-----SD 100-Directives Handbook". Since SHarePoint won't allow blank space to be there, is there a way I can manually indent these child tasks?

This is probably the most head-scratching/annoying request I've come across. So absolutely any help you could provide would be amazing.

Thank you all so, so much.

3
  • You can add one more level of grouping to group the child tasks inside subgroup of "SD 100" like mentioned at: sharepoint.stackexchange.com/questions/293245/… – Ganesh Sanap May 23 at 8:22
  • I actually ended up doing that, but it wasn't what the customer wanted. Basically if I could get rid of the dashes, and keep those rows where they are, I'd be fine. Can I change the font of the dashes to white? That could solve the problem. – Chris May 23 at 13:13
  • I'm also trying to see if possibly I could use a power automate workflow to remove the dashes. Nothing has worked so far. – Chris May 23 at 15:58
1

Would this column formatting code work for you? If the file name starts with 4 dashes, it adds 25px padding-left and replaces the dashes with 4 spaces. You could add multiple conditions if required (such as 5 dashes = additional padding, etc).

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "style": {
        "padding-left": "=if(@currentField startsWith '----', '25px',''"
      }
    },
    {
      "elmType": "span",
      "txtContent": "=replace([$FileLeafRef],'----','    '"
    }
  ]
}

Without Formatting: enter image description here

With Formatting: enter image description here

2
  • This script worked perfectly! Thanks a bunch for that. However, the customer still wants the rows which have those dashes to be indented by a length of about 4 dashes worth. I'm not sure if it's possible to do that for specific items in that column. – Chris May 24 at 19:11
  • I guess my question now is, can I remove the dashes while maintaining the indent or padding on the left? – Chris May 24 at 19:32
0

Adding a second answer which uses the same concept as my other answer but includes renaming the files:

The first thing you'll need to do is identify which documents need to be indented. In my previous answer I used the file name starts with "----". This time, I'm going to use a yes/no column "isChild". You could also use a choice column if you needed to use multiple levels of indentation. Of course, you may already have your own way of fulfilling this requirement.

The column formatting code for my scenario is now:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "style": {
        "padding-left": "=if([$isChild], '25px',''"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}

The padding-left can obviously be changed from 25px to a more suitable value if required.

Now that the column formatting is in place, the only thing left to do is to rename all the documents and change their "isChild" value to Yes. Power Automate can do this but renaming files is a bit trickier than it should be.

Here is the overview of my Flow: enter image description here

In a bit more detail:

1. Get all files starting with "---- " enter image description here

Filter Query: startswith(FileLeafRef,'---- ')

2. Get the properties of each file enter image description here

3. Send a RestAPI call to rename the file enter image description here

This is the complicated one. My example is using the default "Documents" library. The Uri string uses the library name but the body uses the "ListItemEntityTypeFullName" (I think). I've underlined these parts in red.

The full code for the body is:

{ '__metadata': {'type':
'SP.Data.Shared_x0020_DocumentsItem'},'FileLeafRef': '@{replace(outputs('Get_file_properties')?['body/{Name}'],'---- ','')}'}

Make sure you include any spaces at the beginning of the file name in the replace expression.

If you're having difficulty with this step, I'd recommend do a bit of searching for "renaming sharepoint files with rest api". The specific link I used for reference was this: Renaming SharePoint file using REST API

4. Update the "isChild" field to Yes enter image description here

Once you've built and run this flow (definitely test it on a small sample of documents first), the column formatting should be working and the documents no longer start with "----"

Hopefully you can take parts from this example and get it to work for your situation.

1
  • The code you provided didn't work on that particular column. The "Title Link" column is a Hyperlink/Picture Type, and "Document, Link to a Document" under "Used In". However, I created a calculated column to equal the "Title Link" column. It populated the content, but as text rather than the hyperlink pdfs. So I applied your code to my new column and it worked perfectly. Is there a way I can apply this code so that it'll work for a Hyperlink column? – Chris May 25 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.