Hi all!
The OnSuccess attribute of my form should work like this:
If(form mode= new), it should create a new record on another SP List( tbComentario_appDealReview )
If(form mode= edit), it should update the record created on the submit of the newform, but if I create the record direct on the SP List, that parts works like a charm
SP Lists:
- tbOportunity_appDealReview, thats the form DataSource
- tbComentario_appDealReview, Fields of the list { tbOportunity_ID (FK of the tbOportunity_appDealReview ), Comentario (text)}
This is the part of code that doesn't work:
FormMode.New,
Patch(
tbComentario_appDealReview,
Defaults(tbComentario_appDealReview),
{
tbOportunity_ID: Self.LastSubmit.OportunityID,//Value(Self.LastSubmit.OportunityID),
Comentario: "[ INICIO " & Text( Now(), "dd/mm/yyyy hh:mm:ss" ) & "]" & Char(13)
}
)
and this is the full OnSuccess attribute code:
// Set last record "Criterio" Value
If(
Self.LastSubmit.ValorTotal >= 10000000,
Patch(
tbOportunity_appDealReview,
Self.LastSubmit,
{Criterio: "1"}
),
Self.LastSubmit.Margem <= 35,
Patch(
tbOportunity_appDealReview,
Self.LastSubmit,
{Criterio: "2"}
),
Self.LastSubmit.Margem > 35 && Self.LastSubmit.Margem <= Self.LastSubmit.MargemTarget,
Patch(
tbOportunity_appDealReview,
Self.LastSubmit,
{Criterio: "3"}
),
Patch(
tbOportunity_appDealReview,
Self.LastSubmit,
{Criterio: "4"}
)
);
Switch(
Self.Mode
//Condition NewForm
,FormMode.New,
Patch(
tbComentario_appDealReview,
Defaults(tbComentario_appDealReview),
{
tbOportunity_ID: Self.LastSubmit.OportunityID,//Value(Self.LastSubmit.OportunityID),
Comentario: "[ INICIO " & Text( Now(), "dd/mm/yyyy hh:mm:ss" ) & "]" & Char(13)
}
)
//Condition EditForm
,FormMode.Edit,
If(
!IsBlank(txtComentario_frmCad.Text),
Patch(
tbComentario_appDealReview,
LookUp(
tbComentario_appDealReview,
tbOportunity_ID = Self.LastSubmit.OportunityID
),
{
Comentario: $"{txtHistorico_frmCad.Text}{Char(13)}[{Text(Now(),"dd/mm/yyyy hh:mm:ss")}] {glbCurrentUserDisplayName}:{Char(13)}{txtComentario_frmCad.Text}{Char(13)}----"
}
)
)
);
UpdateContext({FormVisible: false});
Notify(
"Formulario salvo com sucesso!",
NotificationType.Success
);