cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gorilla_8
Post Prodigy
Post Prodigy

CLEAN THE FIELD WHEN THE USER SAVES UNDER SOME CONDITIONS

I have several forms divided into tabs, with my SharePoint database

 

About the fields:

 

Some fields appear depending on the choices of another field, so I would like to clear the field or reset it only when the user saves and that specific condition is active.

 

For example:

 

There is a field with two choices:

 

Yes or No.

 

If the user chooses "Yes" a multiple line text field appears, and if he chooses "No" the field does not appear and will be reset or cleared when he saves (click on a button)

 

There is also another condition with Checkbox fields, if the user selects the specific option, clears or resets the field when he saves

 

I tried to use a variable to reset, but it does not clear the field, it saves the same way.

 

In my "SubmitButton" it has functions like "Patch", I don't know if it will influence anything.

 

Thanks for all the help!

22 REPLIES 22
Gorilla_8
Post Prodigy
Post Prodigy

@JR-BejeweledOne 

On default:

 

PlainText(ThisItem.NameOfTheField)


JR-BejeweledOne
Super User
Super User

Rather than resetting the field, I would change my default formula.

 

If (

 

FieldX = "Yes", PlainText(ThisItem.NameOfTheField),
""
)

 

What this will do is set the text input to the value of ThisItem.NameOfTheField if the  first field value is 'Yes' and if the First Field value is "No", the text input will be empty.

 

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
Gorilla_8
Post Prodigy
Post Prodigy

@JR-BejeweledOne 

 

Yes, but it resets instantly, I need it to reset just before saving,  that is, when he is able to save he resets if not, no

JR-BejeweledOne
Super User
Super User

Because of your default formula it's not going to reset the way you want it to.

 

Here is a workaround

 

On select of your item set a variable:

 

Set(varXXX, PlainText(ThisItem.NameOfTheField))

 

Set your default formula to varXXX

 

On save

 

If(FieldXXx = "No", Set(varXXXX, ""))



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
Gorilla_8
Post Prodigy
Post Prodigy

@JR-BejeweledOne 

 

Thanks for the helP!

 

I made a variable before the patch on the save button to set the variable "true", and when I put the variable name in the field reset, it doesn't work, why?

JR-BejeweledOne
Super User
Super User

If you are going to do it that way rather than what I recommended, then create that variable on App start and set it to false, then in your save button, you need 2 statements, Set(varReset, true); Set (varReset, false)



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
Gorilla_8
Post Prodigy
Post Prodigy

@JR-BejeweledOne 

 

If I use your solution the filed instantly resets

I made this code:

If(
    'BI?Radio_3'.Selected.Value = "Não";
    Set(
        resetItem;
        true
    );
    If(
        'BI?Radio_3'.Selected.Value = "Sim";
        Set(
            resetItem;
            false
        )
    )
)

 

When it is "No" it resets, when it is "Yes", it does not, and the property of the field where I want to reset this with the variable: "resetItem"

 

But do not reset the field!

JR-BejeweledOne
Super User
Super User

Here is the issue.  It has to do with your default formula.    This is why Reset is not working the way you want.    Reset only resets it back to the default value.    Your default value points to the value of another field.   In order for reset to work the way you want, the other field has to be reset first.

 

Here is what you need to do.   Keep your new formula and change your default formula on the text field like this:

 

If (

 

'BI?Radio_3'.Selected.Value = "Yes", PlainText(ThisItem.NameOfTheField),
'BI?Radio_3'.Selected.Value = "No" And resetItem, ""
)

 

Make sure you change resetItem back to false after you patch your item to your SharePoint list.

 

 

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
Gorilla_8
Post Prodigy
Post Prodigy

@JR-BejeweledOne 

 

Sorry, I don't understand...

Here's my code:

If(
    ObrigatoriedadeChoice_3.Selected.Value = "N/A";
    Set(
        resetLegislacao;
        true
    );;
    Set(
        resetPlanoDeNegocio;
        true
    );
    Set(
        resetLegislacao;
        false
    );;
    Set(
        resetPlanoDeNegocio;
        false
    )
);;
If(
    ObrigatoriedadeChoice_3.Selected.Value = "Determinação da Alta Direção";
    Set(
        resetLegislacao;
        true
    );;
    Set(
        resetPlanoDeNegocio;
        true
    );
    Set(
        resetLegislacao;
        false
    );;
    Set(
        resetPlanoDeNegocio;
        false
    )
);;
If(
    ObrigatoriedadeChoice_3.Selected.Value = "Atualização Tecnológica; Correção de problema (causa de incidente de TIC)";
    Set(
        resetLegislacao;
        true
    );;
    Set(
        resetPlanoDeNegocio;
        true
    );
    Set(
        resetLegislacao;
        false
    );;
    Set(
        resetPlanoDeNegocio;
        false
    )
);;
If(
    ObrigatoriedadeChoice_3.Selected.Value = "Exigência Legal";
    Set(
        resetPlanoDeNegocio;
        true
    );
    Set(
        resetLegislacao;
        false
    )
);;
If(
    ObrigatoriedadeChoice_3.Selected.Value = "Instrumento Normativo";
    Set(
        resetPlanoDeNegocio;
        true
    );
    Set(
        resetLegislacao;
        false
    )
);;
If(
    ObrigatoriedadeChoice_3.Selected.Value = "Estratégico (PN)";
    Set(
        resetLegislacao;
        true
    );
    Set(
        resetPlanoDeNegocio;
        false
    )
);;
If(
    varMode = "New";
    If(
        !IsBlank(DataCardValue10_3.Selected.Value);
        If(
            'BI?Radio_3'.Selected.Value = "Não";
            Set(
                resetItem;
                true
            );
            Set(
                resetItem;
                false
            )
        );;
        /*FormGeralNew.Valid*/
Patch(
            FichaDeDemanda;
            Defaults(FichaDeDemanda);
            FormGeralNew.Updates;
            FormJustificativa.Updates;
            FormCustosEBeneficios.Updates;
            FormResultadosEsperadosNew.Updates;
            FormInformaçõesComplementares.Updates;
            FormAnexosNew.Updates
        );;
        Set(
            varID;
            Last(FichaDeDemanda).ID
        );;
        Set(
            varPopSalvar;
            false
        )/*;;SubmitForm(FormNewItemDemanda)*/;;
        Notify(
            "As informações da demanda foram salvas em “rascunho”";
            NotificationType.Success
        );;
        Navigate(
            Demandas;
            ScreenTransition.Cover
        );
        Notify(
            "Não foi possível salvar. A informação “Área Demandante” é de preenchimento obrigatório!";
            NotificationType.Error
        );;
        Set(
            varSalvarRascunho;
            false
        );;
        UpdateContext({varBorder: true});;
        Select(btnGeralTab_3);;
        Set(
            varPopSalvar;
            false
        )
    );
    If(
        varMode = "Edit" && !IsBlank(DataCardValue10_3.Selected.Value);
      /*FormGeralNew.Valid*/
        If(
            'BI?Radio_3'.Selected.Value = "Não";
            Set(
                resetItem;
                true
            );;
            If(
                'BI?Radio_3'.Selected.Value = "Sim";
                Set(
                    resetItem;
                    false
                )
            )
        );;
        Patch(
            FichaDeDemanda;
            {ID: GaleriaDemanda.Selected.ID};
            FormGeralNew.Updates;
            FormJustificativa.Updates;
            FormCustosEBeneficios.Updates;
            FormResultadosEsperadosNew.Updates;
            FormInformaçõesComplementares.Updates;
            FormAnexosNew.Updates
        );;
        Set(
            resetItem;
            false
        )
    );;
    Notify(
        "Atualizado com sucesso!";
        NotificationType.Success
    );;
    Set(
        varPopSalvar;
        false
    );
    Notify(
        "Não foi possível salvar. A informação “Área Demandante” é de preenchimento obrigatório!";
        NotificationType.Error
    );;
    Set(
        varSalvarRascunho;
        false
    );;
    UpdateContext({varBorder: true});;
    Select(btnGeralTab_3);;
    Set(
        varPopSalvar;
        false
    )
)
/*
    SubmitForm(FormSalvarElaboração);;
    ResetForm(FormSalvarElaboração)*//*;;
    Navigate(
        Demandas;
        ScreenTransition.Cover
    )*/
    /*
    Patch(
        FichaDeDemanda;
        {ID: GaleriaDemanda.Selected.ID};
        FormGeral.Updates;
        FormPartesInteressadasViewAndEdit.Updates;
        FormAlinhamentoEstratégicoViewAndEdit.Updates;
        FormResultadosEsperadosViewAndEdit.Updates;
        FormInformaçõesComplementaresViewAndEdit.Updates;
        FormAnexosViewAndEdit.Updates
    );;
    Notify(
        "Atualizado com sucesso!";
        NotificationType.Success
    );;
    Navigate(
        DEMANDA;
        ScreenTransition.Cover
    )
)*/
JR-BejeweledOne
Super User
Super User

Where is this code?



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,983)