cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Super User
Super User

Re: Ref number changes when viewing an already submitted record

@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

Highlighted
Post Prodigy
Post Prodigy

Re: Ref number changes when viewing an already submitted record

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

Re: Ref number changes when viewing an already submitted record

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.

 

Highlighted
Post Prodigy
Post Prodigy

Re: Ref number changes when viewing an already submitted record

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

Highlighted
Post Prodigy
Post Prodigy

Re: Ref number changes when viewing an already submitted record

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?

Highlighted
Super User
Super User

Re: Ref number changes when viewing an already submitted record

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.

Highlighted
Super User
Super User

Re: Ref number changes when viewing an already submitted record

@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

Highlighted
Post Prodigy
Post Prodigy

Re: Ref number changes when viewing an already submitted record

@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

 

Highlighted
Super User
Super User

Re: Ref number changes when viewing an already submitted record

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

Highlighted
Super User
Super User

Re: Ref number changes when viewing an already submitted record

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.

Highlighted
Post Prodigy
Post Prodigy

Re: Ref number changes when viewing an already submitted record

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
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (3,736)