Hi, I have an issue writing back to my SP List. I have a form the either creates a new record or updates an existing one. No problem so far. I also have some data coming from some other dropdowns that I need to add to the SP record. So I need to submit the for and then Patch the subsidiary data to the record. If it's an existing record then there isn't an issue but if the Submit is creating a NEW record then the Patch will not work. I've tried creating the record by having the Submit form on the button click and then Patching ON Success of the form being submitted because I thought the record would then exist for the Patch to take place....no luck...it's driving me mad.
Here is the OnSelect of the Save Details Button:
Set(
varStatus,
"Draft"
);
SubmitForm(frmMainDetails);
Here's the On Success of the form aft the Save Details Button has been pressed
If(
varFormMode = 1,
Patch(
Defaults('Change Control - Main'),
LookUp(
'Change Control - Main',
'Change Number' = varFormData.'Change Number'
),
{
'Sponsor Name': ddSponsorChoice.Selected.'Name (Title)',
'Sponsor eMail': lblSponsorChoiceeMail.Text,
'ASM Name': ddASMChoice.Selected.'Name (Title)',
'ASM eMail': lblASMChoiceeMail.Text,
'PM Name': ddPMChoice.Selected.'Name (Title)',
'PM eMail': lblPMChoiceeMail.Text
}
),
If(
varFormMode = 0,
Patch(
'Change Control - Main',
LookUp(
'Change Control - Main',
'Change Number' = varFormData.'Change Number'
),
{
'Sponsor Name': ddSponsorChoice.Selected.'Name (Title)',
'Sponsor eMail': lblSponsorChoiceeMail.Text,
'ASM Name': ddASMChoice.Selected.'Name (Title)',
'ASM eMail': lblASMChoiceeMail.Text,
'PM Name': ddPMChoice.Selected.'Name (Title)',
'PM eMail': lblPMChoiceeMail.Text
}
)
)
);
Any ideas folks?
Thanks
Solved! Go to Solution.
Hello,
I can suggest an easy way :
Add the fields you're trying to patch in your form
Set the datacards defaults values to the values of controls out of the form
Set the datacards .Visible to false
Values will be updated with the submitForm, on newform as on editform 🙂
Hi @psadd2 ,
This is due to Defaults('Change Control - Main') remove this part and trait Patch just like Update.
Defaults don't take lookup, basically You use it to create a new record that it.
In Your scenario when You using normal form the record already exist in both scenario as it was created by submitting for on SubmitForm(frmMainDetails); if you get what I mean so in both scenario Patch will be only an Update to existing record.
Regards
Thanks Seb, I'll give that a go but to be honest I only put the FormMode and the Defaults bit in there as a last resort....my original method did what you have explained above and was still not working.
I'll try again though and let you know
Hello,
I can suggest an easy way :
Add the fields you're trying to patch in your form
Set the datacards defaults values to the values of controls out of the form
Set the datacards .Visible to false
Values will be updated with the submitForm, on newform as on editform 🙂
Hi Seb,
Yes, as I thought this doesn't solve the issue...the Patch still doesn't work.
If I go back into the App and then hit Save Details again.....the Patch works. So it feels to me as though the system is not picking up the fact that the record has been created before the Patch is trying to happen....I've tried adding a Refresh to the data after the Form Submit and before the Patch...but it doesn't work either and I don't think that's the correct practice anyway. Is there some function that can 'delay' the Patch for a few seconds to give the 'record' and opportunity to be created?
Thanks
You can delay by adding a timer object,
In your onsucces : Select(Timer1)
In the Timer1.OnEnd : paste your patch
set a duration of 5000 for 5 sec
I'm assuming 'Change Number' is sort of ID in Your SP List ?
You can try something like this :
If(
varFormMode = 1,
Patch('Change Control - Main'
,
LookUp(
'Change Control - Main',
ID = frmMainDetails.LastSubmit.ID
),
{
'Sponsor Name': ddSponsorChoice.Selected.'Name (Title)',
'Sponsor eMail': lblSponsorChoiceeMail.Text,
'ASM Name': ddASMChoice.Selected.'Name (Title)',
'ASM eMail': lblASMChoiceeMail.Text,
'PM Name': ddPMChoice.Selected.'Name (Title)',
'PM eMail': lblPMChoiceeMail.Text
}
),
If(
varFormMode = 0,
Patch(
'Change Control - Main',
LookUp(
'Change Control - Main',
'Change Number' = varFormData.'Change Number'
),
{
'Sponsor Name': ddSponsorChoice.Selected.'Name (Title)',
'Sponsor eMail': lblSponsorChoiceeMail.Text,
'ASM Name': ddASMChoice.Selected.'Name (Title)',
'ASM eMail': lblASMChoiceeMail.Text,
'PM Name': ddPMChoice.Selected.'Name (Title)',
'PM eMail': lblPMChoiceeMail.Text
}
)
)
);
use
LastSubmit
Function to Your advantage if You just patching to last created record it should Patch it on fly without any Delay options.
I think the issue is with Your variable and not the patch so it's good to check
Regards
Thanks for the response David....I've not played around with the Timer control so I've given it a whirl....not working yet, but that's probably down to me. I'll keep trying and see if I get anywhere.
Thanks Seb....okay I will try this one...I'll let you know if I get it working or not.
Thanks David....yep, I had considered doing this. The Patch data comes from another part of the App and I was trying to avoid a trail of cascading data.....but you are probably right...I may have to revert to this.
User | Count |
---|---|
125 | |
87 | |
86 | |
75 | |
69 |
User | Count |
---|---|
215 | |
181 | |
139 | |
97 | |
83 |