cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lefty
Impactful Individual
Impactful Individual

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

Lefty
Impactful Individual
Impactful Individual

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
Super User

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.

 

Lefty
Impactful Individual
Impactful Individual

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

Lefty
Impactful Individual
Impactful Individual

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.

Lefty
Impactful Individual
Impactful Individual

@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.

Lefty
Impactful Individual
Impactful Individual

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?

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

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