Skip to main content

Search

Expressions, Placeholders and JS Functions Cheatsheet

Featured

Comments

4 comments

  • Christof

    Thanks for sharing all your expression samples and posting this idea!
    These are for sure very useful snippet samples and could be a good start for a new knowledge base article which we continuously extend with more collected samples during time.
    Some functionalities definitely deserve its own topical article but such mentioned small snippets are predestined to get listed in a cheat sheet article.
    We planned already to create more feature and function articles with are referenced directly in Solution Studio on the configuration places but as well accessible here on the portal.

    Updated:
    Instead of transferring the useful expressions to a knowledge base article, we moved this post to the discussions topic for continuous growth by new comments from all community members.

    Let's continue collecting expressions for the Cheatsheet here, 'cause...

    Sharing is caring!

    0
  • Christof

    EvaluateExpression and GetFirstValueForQuery function
    Use case: Manage Texts with placeholders for outgoing emails in lists instead hardcoded in action configuration (load text and replace placeholders): 

    [[@Functions.EvaluateExpression([[@Web.GetFirstValueForQuery('[[@Web.ServerRelativeUrl]]/Lists/EmailTextVorlagen', '<Where><Eq><FieldRef Name="Case" /><Value Type="Text">Sitzung abgeschlossen</Value></Eq></Where>', 'Subject')]])]]

     

    More Date Placeholders & Functions to format date & time values:

    [[=[[YourDateField]].localeFormat('dd.MM.yyyy, HH.mm')]]
    Return: "15.02.2024, 09.30"
    [[=[[YourDateField]].toLocaleString('de-CH',{hour24: false})]]
    Return: "15.2.2024, 09:30:00"
    0
  • Christof

    When using new Date() in Things in background e.g. in Add list item as Triggered Action, you'll recognize the date & time is from server: UTC time (time zone)

    Use the following function to convert date & time into SharePoint site's local time (Time zone from site's Regional Settings)

    =[[@Functions.UTCToLocalTime(new Date())]]
    Returns current date & time of SharePoint site's time zone. e.g. UTC+2: 2024-03-19T14:13:02.538Z


    If you want use it as formatted text output, nest the functions like this:

    [[=[[@Functions.UTCToLocalTime(new Date())]].format("dd.MM.yyyy HH:mm")]]
    Return: "15.02.2024 09.30" (time of SP sites time zone e.g. UTC+2)
    0
  • Christof

    Format numbers with leading zeros. E.g. Project numbers like PR00034

    Earlier i did it with this expression (gets project with highest nr, add +1, set max leading zeros and cut from left to desired amount of digits):

    var nextProjectNr = (1 + Number([[@Functions.GetFirstValueForQuery('Lists/Projects', '<View Scope="Recursive"><Query><OrderBy><FieldRef Name="ProjectNrINT" Ascending="FALSE" /></OrderBy></Query></View>', 'ProjectNrINT')]]));
    var leadingZeroNumber = "00000" + nextProjectNr;
    nextProjectNr = leadingZeroNumber.substr(leadingZeroNumber.length - 5);
    return nextProjectNr;

     It works well, but there is a more straightforward way with padStart() js function:

    var nextProjectNr = (1 + Number([[@Functions.GetFirstValueForQuery('Lists/Projects', '<View Scope="Recursive"><Query><OrderBy><FieldRef Name="ProjectNrINT" Ascending="FALSE" /></OrderBy></Query></View>', 'ProjectNrINT')]]));
    nextProjectNr = nextProjectNr.toString().padStart(5, "0");
    return nextProjectNr;

    Notice: The number needs to be a string when using padStart()

    0

Please sign in to leave a comment.