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 / Context Variable 'losi...
Power Apps
Answered

Context Variable 'losing' value

(0) ShareShare
ReportReport
Posted on by 8
I have recently been having issue with Canvas app. I predominately use Context Variables rather than Global Variables as I have multiple screens and are only relevant to the Screen I am on.
This is a Dynamic Catalogue Screen allows me to check  Catalogue allocations against various levels, so I need to query SQL Tables in order to retrieve the relevant Catalogues.
As part of the Save Record, I have code to be able to update each of the lower levels with the Catalogue information.
 
If I look at the value of the LocalCatalogueList , it is correctly stating that the value is PartsSTD,
 
 
However, if I hover over the next UpdateContext for the Same Variable it believes the value to be blank.
It is supposed to trim off the last , character prior to triggering a SQL Stored Procedure which will update the relevant Catalogues.
However, it is currently passing the Catalogue Parameter as blank.
 
 
This has been functioning perfectly up until very recently, (within last 3/4 weeks)
 
 I would appreciate any suggestions for me to be able to rectify this.
Thank you.
 
I have the same question (0)
  • Suggested answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    Hello @mwalkerk
     
    Yes, you can definitely use a different variable instead of overwriting the same one. For example, keep your original LocalCatalogueList intact and create a new context variable for the trimmed version:
    UpdateContext({ TrimmedCatalogueList: Left(LocalCatalogueList, Len(LocalCatalogueList) - 1) });
    //Use this variable in your automation..

    Alternative Approach – If the trim/substring logic is the only issue, you could also compute it in the formula used in the SQL call directly, rather than relying on the UpdateContext step.

     

    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
    ---------------------------------------------------------------------------------
     
    📩 Need more help? Mention @Kalathiya anytime!
    ✔️ Don’t forget to Accept as Solution if this guidance worked for you.
    💛 Your Like motivates me to keep helping!
  • mwalkerk Profile Picture
    8 on at
    Thank you for your suggestion @Kalathiya, I have tried your suggestion but unfortunately it didn't resolve my issue.
     
    I have also tried to move the trimming Update to within the original UpdateContext, as can be seen below. 
    • At the original point (Yellow highlight) the LocalCatalogueList value is Parts-STD.
    • During Trimming (Blue highlight) , the original LocalCatalogueList value is Blank, despite being in the same updatecontext.
    • Execution of Stored Procedure  (Orange highlight) , the LocalTrimmedCatalogueList value is still Blank.
  • Verified answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    Hello @mwalkerk
     
    Oh got it. Why LocalTrimmedCatalogueList is empty when referenced in the same UpdateContext.
     
    LocalTrimmedCatalogueList is empty because variables created with UpdateContext() are evaluated simultaneously, not sequentially.
     
    In your formula, you are:
    Creating LocalCatalogueList, then immediately using LocalCatalogueList to calculate LocalTrimmedCatalogueList. All inside the same UpdateContext() call
     
    Power Apps does not evaluate the first variable and then pass its value to the next one. Instead, every variable on the right-hand side is evaluated using the previous state of the app.
     

    Split the logic into two steps so the second variable can see the first one’s value:

    UpdateContext({
        LocalCatalogueList:
            Concat(
                Switch(
                    locSideTabValue,
                    "Brand",
                        Filter('View.ProdCatalogueBrand', Company = VarCompany && Brand = tbl_Brand.Selected.Brand),
                    "Range",
                        Filter('View.ProdCatalogueRange', Company = VarCompany && Range = tbl_Range.Selected.Range),
                    "SubRange",
                        Filter('View.ProdCatalogueSubRange', Company = VarCompany && SubRange = tbl_SubRange.Selected.SubRange),
                    "Product",
                        Filter('View.ProdCatalogueProduct', Company = VarCompany && Product = tbl_Product.Selected.Product)
                ),
                Catalogue & ","
            )
    });
    
    UpdateContext({
        LocalTrimmedCatalogueList:
            Left(LocalCatalogueList, Len(LocalCatalogueList) - 1)
    });
    
    Note: Please correct the table name and variable name if it's wrong. 
     
    Please try this. 
     
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
     
     
     
  • mwalkerk Profile Picture
    8 on at
     
    I really appreciate your advice that you have given,  I understand what you mean in terms of adding the trim into the first UpdateContext.  
    I have been trying out some different variations, and instead of separating the Switch first in its own Update Context, I have moved it directly into the StoredProcedure Call. Thankfully it all appears to be working correctly.
    Thank you.
     
     
    If (
        DuplicateError = true,
        UpdateContext({locShowCatItmDuplicatePopup: true}),
        If (
            tog_CatItmFrm_FilterDown.Value = true,
            Set(
                resultActive,
                'sp-UpdateCats-Active'.StoredUpdateCatalogues(
                    {
                        Level: locSideTabValue,
                        Name: Switch(
                            locSideTabValue,
                            "Brand",
                            tbl_Brand.Selected.Brand,
                            "Range",
                            tbl_Range.Selected.Range,
                            "SubRange",
                            tbl_SubRange.Selected.SubRange,
                            "Product",
                            tbl_Product.Selected.Product
                        ),
                        Catalogue: Concat(
                            Switch(
                                locSideTabValue,
                                "Brand",
                                Filter(
                                    'View.ProdCatalogueBrand',
                                    Company = VarCompany && Brand = tbl_Brand.Selected.Brand
                                ),
                                "Range",
                                Filter(
                                    'View.ProdCatalogueRange',
                                    Company = VarCompany && Range = tbl_Range.Selected.Range
                                ),
                                "SubRange",
                                Filter(
                                    'View.ProdCatalogueSubRange',
                                    Company = VarCompany && SubRange = tbl_SubRange.Selected.SubRange
                                ),
                                "Product",
                                Filter(
                                    'View.ProdCatalogueProduct',
                                    Company = VarCompany && Product = tbl_Product.Selected.Product
                                )
                            ),
                            Catalogue,
                            ","
                        ),
                        Active: If(
                            Boolean(tog_CatItmFrm_Active.Value),
                            1,
                            0
                        ),
                        CompanyId: VarCompanyId,
                        User: User().FullName
                    }
                ).ReturnCode
            )
        );

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard