Set default value for handling null values in Entra data

Michael Fleet 101 Reputation points
2025-04-24T17:45:59.1833333+00:00

With reference to my previous question -

https://learn.microsoft.com/en-us/answers/questions/2244994/sort-by-lastsignindatetime-in-logic-app

(thanks to @RithwikBojja and @chrischin )

I need to set the last sign in date/time to a value if it's currently null. Here's the section of my Logic App for dealing with it -

User's image User's image

User's image

User's image

const entradata = workflowContext.actions.Parse_the_Entra_data.outputs.body;
const entra_users = Array.isArray(entradata) ? entradata : entradata.value;
function parseDate(user) {
    return user.signInActivity && user.signInActivity.lastSignInDateTime
        ? new Date(user.signInActivity.lastSignInDateTime)
        : null;
}
const ri_sort_json = [...entra_users].sort((a, b) => {
    const dateA = parseDate(a);
    const dateB = parseDate(b);
    if (dateA && dateB) return dateB - dateA;
    else if (dateA) return -1;
    else if (dateB) return 1;
    else return 0;
});
return ri_sort_json;

However, I'm still seeing null values in the output resulting in a parse failure. Any ideas?

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,488 questions
{count} votes

Accepted answer
  1. RithwikBojja 2,325 Reputation points Microsoft External Staff Moderator
    2025-04-25T03:15:48.8633333+00:00

    Hi @Michael Fleet ,

    To set default value, you can use below design which does the same:

    Here, I have set defaultdate in inline code itself:enter image description here

    
    const rithdata = workflowContext.actions.Parse_JSON.outputs.body;
    
    const cho_users = Array.isArray(rithdata) ? rithdata : rithdata.value;
    
    const DeafultDate = new Date("2000-01-01T00:00:00Z");
    
    function parseDate(rith) {
    
        return rith.signInActivity && rith.signInActivity.lastSignInDateTime
    
            ? new Date(rith.signInActivity.lastSignInDateTime)
    
            : DeafultDate;
    
    }
    
    const cho_sort_json = [...cho_users].sort((a, b) => {
    
        const dateA = parseDate(a);
    
        const dateB = parseDate(b);
    
        return dateB - dateA;
    
    });
    
    cho_sort_json.forEach(user => {
    
        if (!user.signInActivity) {
    
            user.signInActivity = {};
    
        }
    
        if (!user.signInActivity.lastSignInDateTime) {
    
            user.signInActivity.lastSignInDateTime = DeafultDate.toISOString();
    
        }
    
    });
    
    return cho_sort_json;
    
    

    Output:

    enter image description here


    If this answer was helpful, please click "Accept the answer" and mark Yes, as this can help other community members.

    enter image description here

    If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.