Hi all code gurus including
@RandyHayes , @mdevaney , @Pstork1 , @timl
This has been driving me mad all day (still not solved) - I have posted a lot of code here more for a second set of eyes, but to summarise.
- We are transitioning from an "old" process to a "new" one over several months and some jobs can be on both lists. The common field is the Work Order. The (very) old list also has some bad practices in field naming and types.
- As a result, there are three stages of signoff, that are done on the "new" form and are then patched to the equivalent item on the "old" list.
- One piece of logic however if these is something in the field on the "old" list, do not over-write it. The new list items also have a field called P2Defect which is marked as "Yes" if there is something in the "Old" list matching.
So to the issue - the patch actually works perfectly, but on each occasion creates two (always 2) blank records in the "new" list.
I have cross-tested it is picking up the correct ID and Work Order (which it is), but these blank records just keep growing (a lot of field staff with iPads closing jobs - also does it on PCs).
First piece of code on the gallery OnSelect choosing the record (I have gone back to some "long" code in a bit of desperation)
UpdateContext(
{
var_P2Rec:
If(
ThisItem.P2Defect = "Yes",
LookUp(
P2List,
'Work Order' = gblWO
),
Blank()
)
}
);
UpdateContext(
{
var_ID:
If(
!IsBlank(var_P2Rec._ID),
var_P2Rec._ID,
0
)
}
)
works perfectly and picks up the correct record and ID from the "old" list (or sets the variable to zero).
This then runs on the Form OnSuccess - no errors, patches the correct record but gives two bonus blank ones on the "new" list (which the form is based on). I have structured it so it is hopefully easier to browse through.
UpdateContext({varSubmit: Self.LastSubmit});
If(
var_ID > 0,
With(
{
wCompBy:
If(
!IsBlank(var_P2Rec.'Completed By'.Value),
var_P2Rec.'Completed By'.Value,
If(
Len(varSubmit.CompletedBy) > 0,
LookUp(
colCrew,
FullName = varSubmit.CompletedBy
).Employee,
Blank()
)
),
wCompDate:
If(
Value(var_P2Rec.'Date Completed') > 0,
var_P2Rec.'Date Completed',
If(
Value(varSubmit.DateCompleted) > 0,
varSubmit.DateCompleted,
Blank()
)
),
wSignBy:
If(
!IsBlank(var_P2Rec.'Signoff By'.Value),
var_P2Rec.'Signoff By'.Value,
If(
Len(varSubmit.SignoffBy) > 0,
LookUp(
colCrew,
FullName = varSubmit.SignoffBy
).Employee,
Blank()
)
),
wSignDate:
If(
Value(var_P2Rec.'Signoff Date') > 0,
var_P2Rec.'Signoff Date',
If(
Value(varSubmit.SignoffDate) > 0,
varSubmit.SignoffDate,
Blank()
)
),
wFFABy:
If(
!IsBlank(var_P2Rec.'FFA Close'.Value),
var_P2Rec.'FFA Close'.Value,
If(
Len(varSubmit.FFASignoff) > 0,
LookUp(
colCrew,
FullName = varSubmit.FFASignoff
).Employee,
Blank()
)
),
wFFADate:
If(
Value(var_P2Rec.'FFA Date') > 0,
var_P2Rec.'FFA Date',
If(
Value(varSubmit.FFADate) > 0,
varSubmit.FFADate,
Blank()
)
)
},
Patch(
P2List,
{_ID: var_ID},
{
'Completed By': {Value: wCompBy},
'Date Completed': wCompDate,
'Signoff By': {Value: wSignBy},
'Signoff Date': wSignDate,
'FFA Close': {Value: wFFABy},
'FFA Date': wFFADate
}
)
)
)
Any thoughts would be most welcome.