How to Update a Field through a button's OnSelect Event

%3CLINGO-SUB%20id%3D%22lingo-sub-135818%22%20slang%3D%22en-US%22%3EHow%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135818%22%20slang%3D%22en-US%22%3E%3CP%3EI've%20watched%20quite%20a%20few%20PowerApps%20videos%20this%20weekend%20and%20feel%20I%20have%20enough%20knowledge%20to%20try%20my%20hand%20at%20customizing%20some%20forms%20this%20coming%20week.%20However%2C%20something%20very%20basic%20escapes%20me%20and%20I%20didn't%20see%20it%20addressed%20in%20the%20vids%20I%20have%20watched%20thus%20far.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20InfoPath%20or%20visual%20basic%20like%20environments%20I%20have%20used%20in%20the%20past%20(e.g.%20Access%20modules)%2C%20it%20was%20easy%20to%20update%20a%20field%20via%20a%20button%20push%20event%20(or%20clicking%20some%20button-like%20graphic).%20Something%20like...%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EStatus.Value%20%3D%20%22Complete%22%0A%3C%2FPRE%3E%0A%3CP%3EThis%20does%20not%20seem%20as%20straightforward%20in%20PowerApps.%20In%20the%20form%20below%2C%20I%20want%20a%20quick%20way%20to%20mark%20a%20task%20as%20done%2C%20by%20clicking%20on%20a%20%22button%22.%20I%20would%20probably%20replace%20the%20Status%20dropdown%20with%20a%20read-only%20field%20or%20label%20eventually.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20figured%20this%20formula%20should%20work%2C%20but%20nope.%20What%20am%20I%20doing%20wrong.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F25411iCDBE36E37FB2FD8C%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22screen.png%22%20title%3D%22screen.png%22%20%2F%3E%3C%2FSPAN%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-135818%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerApps%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-185715%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-185715%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20can%20we%20change%20a%20column%20value%20to%20variable%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3BI%20have%26nbsp%3B%20and%20dislike%20columns%20in%20my%20excel.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3BWhen%20the%20user%20clicks%20the%20Like%20button%20under%20the%20image%20I%20want%20the%20column%20value%20to%20be%20increased%20by%201%2C%20same%20for%20dislike%20button.%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%20for%20each%20image%20if%20the%20user%20clicked%20Like%20button%20she%2Fhe%20shouldnt%20be%20able%20to%20click%20dislike%20button%20and%20viceversa.%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20can%20I%20do%20this%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-137843%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-137843%22%20slang%3D%22en-US%22%3E%3CP%3EOn%20another%20app%2C%20I%20got%20the%20same%20error%3A%3C%2FP%3E%0A%3CPRE%3E%22An%20entry%20is%20required%20or%20has%20an%20invalid%20value.%20Please%20correct%20and%20try%20again.%22%3C%2FPRE%3E%0A%3CP%3EIn%20this%20case%2C%20I%20didn't%20have%20an%20ID%20field%20on%20the%20form.%20In%20this%20case%2C%20I%20had%20a%20Title%20field%20displayed%20as%20read-only.%20It%20was%20a%20required%20field%2C%20but%20I%20didn't%20create%20new%20items%20using%20this%20form%2C%20so%20I%20needed%20this%20field%20to%20be%20read-only.%26nbsp%3B%20When%20I%20flipped%20it%20back%20to%20editable%2C%20the%20error%20went%20away.%20So%20my%20workaround%20was%20to%20change%20the%20visible%20property%20to%20hide%20the%20field%20and%20to%20display%20the%20Text%20of%20that%20field%20using%20a%20Label%20control.%20All%20is%20well%20in%20my%20form%20universe%20again.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-136673%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-136673%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20Peter%2C%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20tried%20substituting%20the%20Lookup%20for%20the%20Filter%20and%20could%20not%20resolve%20the%20syntax%20errors.%20I'm%20good%20for%20now.%20I'm%20pretty%20happy%20with%20the%20progress%20over%20a%20couple%20days%20in%20learning%20this%20from%20scratch.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-136636%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-136636%22%20slang%3D%22en-US%22%3E%3CP%3EGood%20to%20see%20you%20found%20a%20working%20solution%2C%20just%20an%20FYI%20on%20your%20code%20you%20might%20be%20able%20to%20replace%20the%20First(Filter('Store%20Task%20Template'%2CID%3DSharePointIntegration.SelectedListItemID))%20with%20Lookup(%3CSPAN%3E'Store%20Task%20Template'%2CID%3DSharePointIntegration.SelectedListItemID%3C%2FSPAN%3E)%20which%20is%20essentially%20the%20same%20thing%20but%20easier%20to%20follow.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowerapps%2Ffunctions%2Ffunction-filter-lookup%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowerapps%2Ffunctions%2Ffunction-filter-lookup%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENice%20work!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-136517%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-136517%22%20slang%3D%22en-US%22%3E%3CP%3EI%20was%20getting%20a%20nasty%20error%20on%20submit%20with%20the%20last%20solution%3A%26nbsp%3B%26nbsp%3B%22An%20entry%20is%20required%20or%20has%20an%20invalid%20value.%20Please%20correct%20and%20try%20again.%22%26nbsp%3B%20If%20you%20click%20on%20Submit%20again%2C%20the%20error%20goes%20away.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOthers%20have%20discovered%20that%20this%20error%20is%20caused%20by%20having%20the%20SharePoint%20List%20ID%20field%20on%20the%20form.%20I%20removed%20it%20and%20it%20went%20away.%20However%20I%20need%20to%20access%20the%20ID%20to%20use%20Patch.%20So%20I%20dug%20and%20found%20I%20can%20get%20the%20ID%20from%20the%20SharePointIntegration%20Object%20as%20the%20property%20SelectedListItemID.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWorks%20and%20no%20submit%20error%20message.%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EPatch('Store%20Task%20Template'%2C%0AFirst(Filter('Store%20Task%20Template'%2CID%3DSharePointIntegration.SelectedListItemID))%2C%0A%7B%0A%20%20%20%20Status%3A%7B'%40odata.type'%3A%22%23Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference%22%2C%0A%20%20%20%20Value%3A%22Complete%22%2C%0A%20%20%20%20Id%3A1%0A%20%20%20%20%7D%0A%7D%0A)%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-136498%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-136498%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20working%20solution.%20I%20don't%20know%20if%20it's%20the%20best%20solution.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20OnSelect%20code%20for%20the%20button%20is%3A%3C%2FP%3E%0A%3CPRE%3EPatch('Store%20Task%20Template'%2C%0AFirst(Filter('Store%20Task%20Template'%2CID%3DValue(IDValue.Text)))%2C%0A%7B%0A%20%20%20%20Status%3A%7B'%40odata.type'%3A%22%23Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference%22%2C%0A%20%20%20%20Value%3A%22Complete%22%2C%0A%20%20%20%20Id%3A1%0A%20%20%20%20%7D%0A%7D%0A)%0A%3C%2FPRE%3E%0A%3CP%3EOne%20thing%20I%20like%20is%20that%20it%20updates%20the%20current%20item%20whether%20in%20edit%20more%20or%20display%20mode.%20That%20will%20save%26nbsp%3Bmouseclicks%20for%20the%20end%20user%20who%20just%20wants%20to%20mark%20a%20task%20as%20done.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20would%20like%20to%20know%20how%20I%20can%20use%20the%20Filter%20to%20get%20the%20current%20item%20without%20having%20to%20look%20up%20the%20ID%20from%20a%20control%20as%20I%20did.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-136241%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-136241%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20Peter%2C%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20gave%20that%20a%20try%20and%20it%20appears%20to%20be%20the%20wrong%20syntax...tried%20various%20versions%20and%20recheck%20field%20and%20control%20names.%20If%20you%20are%20able%20to%20get%20a%20working%20version%20it%20would%20be%20very%20appreciated.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESuggested%20Form%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ETask%20(Title)%20Field%20-%20Text%2C%20Required%3C%2FLI%3E%0A%3CLI%3EDescription%20Field%20-%20Plain%20Text%2C%20Multi-line%3C%2FLI%3E%0A%3CLI%3EStatus%20Field%20-%20Choice%2C%20Required%2C%20%22Not%20Started%22%20(Default)%2C%20%22Started%22%2C%20%22Complete%22%3C%2FLI%3E%0A%3CLI%3EDue%20Date%20Field%20-%20Date%2C%20Required%3C%2FLI%3E%0A%3CLI%3ELink%20Field%20-%20Link%20or%20Picture%20set%20to%20URL%3C%2FLI%3E%0A%3CLI%3EAssignee%20Field%20-%20Name%2FGroup%2C%20Required%3C%2FLI%3E%0A%3CLI%3EButton%20-%20%22Mark%20Completed%22%20Action%3A%20Changes%20Status%20Field%20to%20%22Complete%22%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EI%20tried%20to%20attach%20a%20template%20file%2C%20but%20it's%20not%20allowed%20here.%20PM%20me%20if%20you%20want%20me%20to%20email%20it.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-136203%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-136203%22%20slang%3D%22en-US%22%3E%3CP%3EI%20would%20need%20to%20build%20a%20sharepoint%20list%20and%20powerapp%20to%20test%20this%2C%20but%20what%20I%20would%20try%20is%20setting%20the%20value%20of%20the%20variable%20to%20the%20actual%20record%20that%20the%20dropdown%20in%20looking%20for%2C%20e.g.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESet(varStatus%2C%20Lookup(Status%2C%20Value%20%3D%20%22Started%22))%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%20me%20know%20if%20trying%20something%20like%20this%20works%20and%20if%20not%20I%20will%20run%20up%20a%20test%20app%20for%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135964%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135964%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20Peter%2C%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20is%20throwing%20an%20error.%20I%20tried%20both%20ThisItem.Default%20and%20Parent.Default%2C%20but%20the%20real%20error%20seems%20to%20be%20the%20variable%20isn't%20of%20the%20type%20expected.%20I%20have%20set%20it%20as%20a%20Text%20variable.%20I%20also%20noticed%20that%20the%20values%20available%20to%20the%20dropdown%20(Not%20Started%2C%20Started%2C%20and%20Complete)%20don't%20show%20up%20either%20with%20this.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F25430iD10B23D20F6435C2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22recordvalue.png%22%20title%3D%22recordvalue.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135840%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135840%22%20slang%3D%22en-US%22%3EVery%20helpful%20Peter.%20It%E2%80%99s%20late%20in%20my%20time%20zone.%20Will%20try%20when%20I%20get%20to%20work.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135839%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135839%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20set%20it%20in%20the%20formula%20for%20the%20field%20Default.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYes%20that%20can%20work%2C%20or%20you%20can%20use%20an%20if%20statement%20in%20the%20formula%2C%20if%20it%20is%20on%20the%20input%20field%20(not%20the%20card)%20it%20could%20be%20if(%20IsBlank(VariableX)%2C%20ThisItem.Default%2C%20VariableX)%20that%20what%20the%20default%20value%20of%20the%20card%20is%20the%20original%20data%20from%20the%20database%20and%20the%20field%20gets%20a%20different%20default%20value%20based%20on%20if%20the%20variable%20has%20data%20or%20not.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135838%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135838%22%20slang%3D%22en-US%22%3EPeter%3CBR%20%2F%3EDo%20I%20set%20the%20Default%20property%20of%20the%20target%20field%20(Status)%20to%20the%20variable%20in%20runtime%20programmatically%20or%20do%20I%20do%20it%20in%20advance%20as%20a%20formula%3F%20%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20it%E2%80%99s%20it%20advance%2C%20then%20I%20think%20I%20need%20to%20capture%20the%20field%20value%20and%20put%20it%20in%20the%20variable%20on%20load%2C%20so%20that%20the%20field%20can%20be%20populated%20with%20that%20value%3B%20then%20have%20my%20button%20change%20the%20variable%20to%20the%20new%20value%20(e.g.%20%E2%80%9CComplete%E2%80%9D)%3B%20then%20the%20field%20will%20reflect%20the%20updated%20value.%20Is%20this%20correct%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135834%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135834%22%20slang%3D%22en-US%22%3EHey%20Peter%3CBR%20%2F%3EThanks%20I%20will%20read%20that%20tomorrow%20AM.%20That%20would%20mean%2C%20I%20am%20assuming%20that%20the%20variable%20needs%20to%20be%20initialized%20to%20the%20existing%20value%20of%20the%20status%20field%20when%20the%20form%20is%20loaded.%20%3CBR%20%2F%3EI%20will%20study%20it%20and%20mark%20this%20as%20the%20solution%20once%20I%20have%20it%20working.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135826%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135826%22%20slang%3D%22en-US%22%3E%3CP%3EI%20should%20mention%20that%20if%20you%20want%20to%20use%20the%20variable%20as%20the%20value%20of%20an%20input%20field%20you%20can%20set%20the%20Default%20property%20of%20the%20field%20to%20the%20variable.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135825%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Update%20a%20Field%20through%20a%20button's%20OnSelect%20Event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135825%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20would%20need%20to%20set%20the%20value%20of%20the%20field%20you%20want%20to%20change%20to%20a%20variable%20and%20then%20set%20that%20variable%20with%20the%20OnSelect%20event.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDepending%20if%20you%20need%20this%20across%20multiple%20pages%20you%20can%20use%20either%20a%20local%20(context)%20or%20global%20variable.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20set%20a%20local%20variable%20you%20can%20use%20%3CSTRONG%3EUpdateContext%3C%2FSTRONG%3E%3CSPAN%3E(%20%7B%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EContextVariable1%3C%2FEM%3E%3CSPAN%3E%3A%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EValue1%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%7D%20)%3C%2FSPAN%3E%3CSTRONG%20class%3D%22%22%3E%26nbsp%3B%3C%2FSTRONG%3Eor%20like%20these%202%20examples%3A%26nbsp%3B%3CSTRONG%20class%3D%22%22%3EUpdateContext(%20%7B%20CountNumber%3A%26nbsp%3B1%26nbsp%3B%7D%20)%26nbsp%3B%3C%2FSTRONG%3Eor%26nbsp%3B%3CSTRONG%20class%3D%22%22%3EUpdateContext(%20%7B%20Name%3A%20%22John%22%7D%20)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%20class%3D%22%22%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ETo%20set%20a%20global%20variable%20you%20can%20use%26nbsp%3B%3CSTRONG%20class%3D%22x-hidden-focus%22%3ESet%3C%2FSTRONG%3E%3CSPAN%3E(%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EVariableName%3C%2FEM%3E%3CSPAN%3E%2C%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EValue%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B)%20or%20like%20these%202%20examples%3A%26nbsp%3BSet%3CSTRONG%20class%3D%22%22%3E(%26nbsp%3B%20CountNumber%2C%201%26nbsp%3B%20)%26nbsp%3B%3C%2FSTRONG%3Eor%20Set%3CSTRONG%20class%3D%22%22%3E(%20Name%2C%20%22John%22%20)%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ETo%20use%20show%20either%20of%20the%20above%20variable%20types%20is%20as%20easy%20as%20putting%20the%20variable%20name%20in%20the%20text%20property%20of%20the%20object%20you%20want%20to%20use.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ESee%20these%20pages%20for%20more%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowerapps%2Ffunctions%2Ffunction-updatecontext%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowerapps%2Ffunctions%2Ffunction-updatecontext%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowerapps%2Ffunctions%2Ffunction-set%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowerapps%2Ffunctions%2Ffunction-set%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Deleted
Not applicable

I've watched quite a few PowerApps videos this weekend and feel I have enough knowledge to try my hand at customizing some forms this coming week. However, something very basic escapes me and I didn't see it addressed in the vids I have watched thus far. 

In InfoPath or visual basic like environments I have used in the past (e.g. Access modules), it was easy to update a field via a button push event (or clicking some button-like graphic). Something like...

 

Status.Value = "Complete"

This does not seem as straightforward in PowerApps. In the form below, I want a quick way to mark a task as done, by clicking on a "button". I would probably replace the Status dropdown with a read-only field or label eventually. 

I figured this formula should work, but nope. What am I doing wrong.

screen.png 

 

 

 

 

 

 

 

 

15 Replies

You would need to set the value of the field you want to change to a variable and then set that variable with the OnSelect event.

 

Depending if you need this across multiple pages you can use either a local (context) or global variable.

 

To set a local variable you can use UpdateContext( { ContextVariable1Value1 } ) or like these 2 examples: UpdateContext( { CountNumber: 1 } ) or UpdateContext( { Name: "John"} )

 

To set a global variable you can use SetVariableNameValue ) or like these 2 examples: Set(  CountNumber, 1  ) or Set( Name, "John" )

 

To use show either of the above variable types is as easy as putting the variable name in the text property of the object you want to use.

 

See these pages for more:

https://docs.microsoft.com/en-us/powerapps/functions/function-updatecontext

https://docs.microsoft.com/en-us/powerapps/functions/function-set

I should mention that if you want to use the variable as the value of an input field you can set the Default property of the field to the variable.

Hey Peter
Thanks I will read that tomorrow AM. That would mean, I am assuming that the variable needs to be initialized to the existing value of the status field when the form is loaded.
I will study it and mark this as the solution once I have it working.
Peter
Do I set the Default property of the target field (Status) to the variable in runtime programmatically or do I do it in advance as a formula?

If it’s it advance, then I think I need to capture the field value and put it in the variable on load, so that the field can be populated with that value; then have my button change the variable to the new value (e.g. “Complete”); then the field will reflect the updated value. Is this correct?

You set it in the formula for the field Default.

 

Yes that can work, or you can use an if statement in the formula, if it is on the input field (not the card) it could be if( IsBlank(VariableX), ThisItem.Default, VariableX) that what the default value of the card is the original data from the database and the field gets a different default value based on if the variable has data or not.

Very helpful Peter. It’s late in my time zone. Will try when I get to work.

Hey Peter, 

 

That is throwing an error. I tried both ThisItem.Default and Parent.Default, but the real error seems to be the variable isn't of the type expected. I have set it as a Text variable. I also noticed that the values available to the dropdown (Not Started, Started, and Complete) don't show up either with this. 

 

recordvalue.png

I would need to build a sharepoint list and powerapp to test this, but what I would try is setting the value of the variable to the actual record that the dropdown in looking for, e.g. 

 

Set(varStatus, Lookup(Status, Value = "Started"))

 

Let me know if trying something like this works and if not I will run up a test app for you.

Hey Peter, 

I gave that a try and it appears to be the wrong syntax...tried various versions and recheck field and control names. If you are able to get a working version it would be very appreciated. 

 

Suggested Form:

 

  • Task (Title) Field - Text, Required
  • Description Field - Plain Text, Multi-line
  • Status Field - Choice, Required, "Not Started" (Default), "Started", "Complete"
  • Due Date Field - Date, Required
  • Link Field - Link or Picture set to URL
  • Assignee Field - Name/Group, Required
  • Button - "Mark Completed" Action: Changes Status Field to "Complete"

I tried to attach a template file, but it's not allowed here. PM me if you want me to email it. 

I have a working solution. I don't know if it's the best solution. 

 

The OnSelect code for the button is:

Patch('Store Task Template',
First(Filter('Store Task Template',ID=Value(IDValue.Text))),
{
    Status:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    Value:"Complete",
    Id:1
    }
}
)

One thing I like is that it updates the current item whether in edit more or display mode. That will save mouseclicks for the end user who just wants to mark a task as done. 

I would like to know how I can use the Filter to get the current item without having to look up the ID from a control as I did. 

 

I was getting a nasty error on submit with the last solution:  "An entry is required or has an invalid value. Please correct and try again."  If you click on Submit again, the error goes away. 

Others have discovered that this error is caused by having the SharePoint List ID field on the form. I removed it and it went away. However I need to access the ID to use Patch. So I dug and found I can get the ID from the SharePointIntegration Object as the property SelectedListItemID. 

Works and no submit error message. 

Patch('Store Task Template',
First(Filter('Store Task Template',ID=SharePointIntegration.SelectedListItemID)),
{
    Status:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
    Value:"Complete",
    Id:1
    }
}
)

 

 

Good to see you found a working solution, just an FYI on your code you might be able to replace the First(Filter('Store Task Template',ID=SharePointIntegration.SelectedListItemID)) with Lookup('Store Task Template',ID=SharePointIntegration.SelectedListItemID) which is essentially the same thing but easier to follow.

https://docs.microsoft.com/en-us/powerapps/functions/function-filter-lookup

 

Nice work!

Thanks Peter, 

I tried substituting the Lookup for the Filter and could not resolve the syntax errors. I'm good for now. I'm pretty happy with the progress over a couple days in learning this from scratch. 

On another app, I got the same error:

"An entry is required or has an invalid value. Please correct and try again."

In this case, I didn't have an ID field on the form. In this case, I had a Title field displayed as read-only. It was a required field, but I didn't create new items using this form, so I needed this field to be read-only.  When I flipped it back to editable, the error went away. So my workaround was to change the visible property to hide the field and to display the Text of that field using a Label control. All is well in my form universe again. 

 

Hi, 

How can we change a column value to variable? 

 I have  and dislike columns in my excel. 

 When the user clicks the Like button under the image I want the column value to be increased by 1, same for dislike button. 

Also for each image if the user clicked Like button she/he shouldnt be able to click dislike button and viceversa. 

How can I do this? 

 

Thanks,