Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

How to set a column in a global variable record to blank?

(0) ShareShare
ReportReport
Posted on by 634

I have a situation where I need to set a part of a global variable(record) to blank if a certain action is taken. I've tried the following but it's a no-go. Is there a way to do this?

 

Set(glbFormData.'First Value', Blank());

UpdateContext({glbFormData.'First Value': Blank()});

 

Categories:
  • Future_Vision Profile Picture
    634 on at
    Re: How to set a column in a global variable record to blank?

    @RandyHayes 

    Description of the controls

    • Source_DC = datacard with custom combobox called Source_CB
    • FirstValue_DC = datacard with custom combobox called FirstValue_CB. Set to DisplayMode.Disabled unless Source_CB value contains "1st" in the selected value
    • AddNewFirst_BTN = Button that sets the visibility of the AddNewFirst_GRP which is a group
    • AddNewFirst_TB = text box where a new value is entered to be added to FirstValue_CB (First Value datasource)
    • AddFirstValueAddCancel_BTN = Performs a patch to the First Value datasource if a value is present in AddNewFirst_TB, sets newFirst to the value of AddNewFirst_TB and resets FirstValue_CB. This button also hides the AddNewFirst_GRP which gives the impression that the action was canceled if no value is entered in AddNewFirst_TB. 

    The idea behind the newFirst variable is it gives me the ability to set the DSI of FirstValue_CB to newFirst if a value is present otherwise use the value of Parent.Default. I was getting stuck when there is a value in FirstValue_CB and the Source_CB was set to a value that didn't contain "1st" in the selected value. FirstValue_CB would still get submitted.

     

    Does that help explain things in a little more detail?

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on at
    Re: How to set a column in a global variable record to blank?

    @Future_Vision 

    Try to cut back on variables and setting variables in OnChange actions.  These will trip you up over and over.  Simply have your formulas reference conditions that you have in your app.

    So, let's say that newFirst (I have no idea what you have for that) is a dropdown in your form called dropdown1.

    Instead of trying to set a variable on the OnChange, you would just change the formula you have to the following:

    {crfeb_firstvalue: 
     If(Self.DisplayMode=DisplayMode.Edit, 
     Coalesce(Dropdown1.Selected.Value, Parent.Default), 
     Blank()
     )
    }
    
    
  • Future_Vision Profile Picture
    634 on at
    Re: How to set a column in a global variable record to blank?

    FirstValue is a field. I revisited another set of fields I was working on and I think this variation might do the trick.

    If(Self.DisplayMode=DisplayMode.Edit, If(IsBlank(newFirst),{crfeb_firstvalue:Parent.Default},newFirst), Blank())

     

    Note that newFirst is a variable being set by another field when that field's value is submitted.

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on at
    Re: How to set a column in a global variable record to blank?

    @Future_Vision 

    Chances are...

     

    Usually when you start introducing in OnChange actions, things are going the wrong way.

    You are trying (in the OnChange) to set a FirstValue to blank.  I would ask this - is the FirstValue a field of your form?  If so, then you should be looking at it from the perspective of the control in the form getting the value it needs based on the condition rather than trying to slip the change in underneath to the form record.

  • Future_Vision Profile Picture
    634 on at
    Re: How to set a column in a global variable record to blank?

    Hmm. Maybe I am overcomplicating things. This seems like a lot of work for little functionality.

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on at
    Re: How to set a column in a global variable record to blank?

    @Future_Vision 

    If you're changing the record variable that is the Item of the editform, it should update the values on the form itself.  However, keep in mind that once a control is changed (i.e. a dropdown, etc) it will retain its value.

     

    So, instead of resetting the form, consider resetting the controls that appear to be losing their values.

  • Future_Vision Profile Picture
    634 on at
    Re: How to set a column in a global variable record to blank?

    Hmmm. ResetForm works to get those values back but it also resets the field I changed that triggers the ResetForm thereby resetting it's value as well.

  • Future_Vision Profile Picture
    634 on at
    Re: How to set a column in a global variable record to blank?

    When I change the combobox that has this formula in the OnChange property it sets that combobox and every other combobox to show no values. At least visually.

     

    If(!("1st" in Source_CB.Selected.crfeb_source), Set(glbFormData, Patch(glbFormData, {crfeb_firstvalue: Blank()})))

     

    If I add a label and set the text to the datacard default value like this then there is data showing since it is pulling from the glbFormVariable. (First Value DC is obviously blank now if I try to access its default)

     

    Source_DC.Default

     

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on at
    Re: How to set a column in a global variable record to blank?

    @Future_Vision 

    Yes, giving the wrong name will certainly do that.  Nothing more frustrating than even misspelling a column and then the designer re-evaluates all the schema before you can correct it.  Once that happens...the designer is "lost".  You've got to exit and start again.  I with there was a "re-evaluate schemas" option in the designer.

     

    As for the other issue you are seeing - can you describe that a little more?

  • Future_Vision Profile Picture
    634 on at
    Re: How to set a column in a global variable record to blank?

    @RandyHayes 
    I see what happened. I used the wrong column name. Should have been crfeb_firstvalue. Error is gone now, however, doing something like this sets all of the fields, that use a DSI, to blank even though the data still exists in the glbFormData variable

     

     

    If(!("1st" in Source_CB.Selected.crfeb_source), Set(glbFormData, Patch(glbFormData, {crfeb_firstvalue: Blank()})))

     

     

    The typical DSI looks like 

    {crfeb_source:Parent.Default}

     

    Is this because the glbFormData variable needs to be reevaluated somehow?

     

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,605 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,946 Most Valuable Professional

Leaderboard