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

Ref number changes when viewing an already submitted record

HI

I thought I could suss this out, When I submit an approved record a ref number is set up via this code :

 

 

 

If(DataCardValue22_5.Value = true, Concatenate("TD-",Text(First(Sort(ListName,Created,Descending)).ID + 1, "[$-en-GB]0000")))

 

 

 But when I re-visit the same screen to navigate to another, the ref number has incremented by 1, i thought If i did this it would work but getting errors:

 

 

If(DataCardValue22_5.Value = true && IsBlank(DataCardValue34_5.Text, Concatenate("PTD-",Text(First(Sort(PermitToDig,Created,Descending)).ID + 1, "[$-en-GB]0000")))

 

 

 

DataCardValue22_5 is my toggle, so when approved the ref number is displayed 

DataCardValue34_5 is my field storing the ref number

 

Is there a way it wont change it if there is already a value in the field?

2 ACCEPTED SOLUTIONS

Accepted Solutions

@Lefty ,

Too much altering code and getting late here . . .now fixed as below

If(
   Self.Value=true,
   Set(
      vNewNo,
      Concatenate(
         "TD-",
         Text(
            First(
               Sort(
                  ListName,
                  Created,
                  Descending
               )
            ).ID + 1, 
           "[$-en-GB]0000"
         )
      )
   )
);
Reset(YourTextBoxName)

On the Default of your Text Box

If(
   !IsBlank(vNewNo) && IsBlank(Self.Text),
   vNewNo,
   Parent.Default
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

Hi @WarrenBelz 

 

Sorry for not coming back, I was off.

I realised I was making this a lot longer than I needed to although your suggestion definitely comes in handy I think I am going to use the following, unless I find a flaw or someone else does :

If(DataCardValue22_5.Value = true && IsBlank(VarRecord.RefNumber), Concatenate("PD-",Text(First(Sort(ListName,Created,Descending)).ID + 1, "[$-en-GB]0000")), Parent.Default)

 

I'll mark both as answers though..... do you see any issues with the above code?

View solution in original post

9 REPLIES 9
WarrenBelz
Super User III
Super User III

Hi @Lefty ,

Put this on your toggle OnChange

If(
   Self.Value=true,
   Set{
      vNewNo,
      Concatenate(
         "TD-",
         Text(
            First(
               Sort(
                  ListName,
                  Created,
                  Descending
               )
            ).ID + 1, 
           "[$-en-GB]0000"
         )
      )
   )
);
Reset(YourTextBoxName)

On the Default of your Text Box

If(
   !IsBlank(vNewNo),
   vNewNo,
   Parent.Default
)

On the end of your Save and screen exit code

Set(vNewNo,Blank())

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

HI @WarrenBelz 

Thanks for your response

 

I think I always get mixed up with this, when I create my form the form is always in FormMode.Edit... I've never changed this as it hasn't caused any noticeable issues. But using your formula, although it's correct won't work in my scenario?

I've put a label on my form to check if the form is in edit or new and its in Edit, how do i fix this please, sorry this is straying away from my original question

I've attempted this: but getting an error see snippet if i remove the curly bracket and use a open bracket i get invalid number of arguments: received 2 expected 3 :

Lefty_0-1595938411593.png

I havent attempted to try the latter 2 parts of your suggestion, as thought this is the main part of the code?

Hi @Lefty ,

I don't think the Mode should matter - also I updated my post a couple of minutes after posting as I had headed in the wrong direction. You simply need to set the field once (hence the one-time Variable) - you could also add

!IsBlank(vNewNo) && IsBlank(Self.Text)

to ensure it is never set again. As for Edit mode, I assume you are using a Patch to write the data? If so, the mode has to be edit to enter the data in it.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

@Lefty ,

Too much altering code and getting late here . . .now fixed as below

If(
   Self.Value=true,
   Set(
      vNewNo,
      Concatenate(
         "TD-",
         Text(
            First(
               Sort(
                  ListName,
                  Created,
                  Descending
               )
            ).ID + 1, 
           "[$-en-GB]0000"
         )
      )
   )
);
Reset(YourTextBoxName)

On the Default of your Text Box

If(
   !IsBlank(vNewNo) && IsBlank(Self.Text),
   vNewNo,
   Parent.Default
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

@WarrenBelz  Thanks

Had to remove the curly brackets next to Set and that accepted it

but on the default property of my text box i get the following:

 

Lefty_0-1595939470324.png

 

@Lefty ,

Get rid of the Self.Text test - I did not think of that one (circular).

It will work without it.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @Lefty ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @WarrenBelz 

 

Sorry for not coming back, I was off.

I realised I was making this a lot longer than I needed to although your suggestion definitely comes in handy I think I am going to use the following, unless I find a flaw or someone else does :

If(DataCardValue22_5.Value = true && IsBlank(VarRecord.RefNumber), Concatenate("PD-",Text(First(Sort(ListName,Created,Descending)).ID + 1, "[$-en-GB]0000")), Parent.Default)

 

I'll mark both as answers though..... do you see any issues with the above code?

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (46,529)