web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Why should records in ...
Power Apps
Unanswered

Why should records in an If formula have the same fields?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

 

 

Can you guess what the JSON string value of ctxJson will be?

 

 

UpdateContext(
 {
 ctxJson: JSON(
 If(
 true,
 {
 onBothRecords: "First record",
 onlyOnFirstRecord: "onlyOnFirstRecord"
 },
 {
 onBothRecords: "Second record",
 onlyOnSecondRecord: "onlyOnSecondRecord"
 }
 )
 )
 }
);

 

 

 

SPOILER:

The answer is:

 

 

{"onBothRecords":"First record"}

 

 

So it seems that only the fields from the first record that are available on both records will be returned, otherwise the "onlyOnFirstRecord" field would have been serialized too.

 

Can somebody post some link(s) to an article or docs where this problem/feature is described? Is this a known issue?

 

PS. I attached an example Power App, so you can see this code in action.

Categories:
  • alaabitar Profile Picture
    1,503 Super User 2024 Season 1 on at

    Hello,

    So I don't know why this is behaving like this but you could do something like

    UpdateContext(
     {
     ctxJson: JSON(
     If(
     true,
     {
     onBothRecords: "First record",
     onlyOnFirstRecord: "onlyOnFirstRecord",
     onlyOnSecondRecord:Blank()
     },
     {
     onBothRecords: "Second record",
     onlyOnSecondRecord: "onlyOnSecondRecord",
     onlyOnFirstRecord:Blank()
     }
     )
     )
     }
    );

    And you will get 

    {"onBothRecords":"First record","onlyOnFirstRecord":"onlyOnFirstRecord","onlyOnSecondRecord":null}

    in the ctxJson variable. At least with the null values you can know from witch json type the variable was filled.

     

    Best regards,

    Alaa

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks @alaabitar , I figured that one out for myself. In my use case I didn't want to add Blank() values, because I was updating a database table and I wanted to only update certain columns based on the if condition. So to get that to work, I need to do something like the following: 

    If(
     myBooleanCondition,
     UpdateContext(
     {
     ctxJson: JSON(
     {
     onBothRecords: "First record",
     onlyOnFirstRecord: "onlyOnFirstRecord"
     }
     )
     }
     ),
     UpdateContext(
     {
     ctxJson: JSON(
     {
     onBothRecords: "Second record",
     onlyOnSecondRecord: "onlyOnSecondRecord"
     }
     )
     }
     )
    )

    But back to my original question, is this behaviour documented somewhere? Or is it a known issue? Please provide some links.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 396 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 323

#3
WarrenBelz Profile Picture

WarrenBelz 193 Most Valuable Professional

Last 30 days Overall leaderboard