Create a timestamp after a field is updated | Community
Skip to main content
RaulOcana
Level 3
February 28, 2020
Solved

Create a timestamp after a field is updated

  • February 28, 2020
  • 1 reply
  • 4166 views

Hi guys,

 

It is possible to insert a date (in a new field) once a recipient's field is updated, for instance, the blacklist field? So we can check when a user opted-in or opted-out?

 

Thank you!

 

Regards,

Raúl

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Milan_Vucetic

Hi @raulocana ,

 

recipient table has a native link to Modified by where datetime is updated when any field is changed.

In case you need a new column you can define a new attribute/column like this and field will contain sysdate when record was inserted (Oracle).

 

If you are using web app (for email opt in/out) you can use JS like this:

 

if ( ctx.vars.recipientId == "" || ctx.vars.recipientId == undefined || ctx.vars.recipientId == null ) {

ctx.recipient.@xtkschema="nms:recipient";
ctx.recipient.@_operation="update";
ctx.recipient.@_key="@id";
ctx.recipient.@lastBlackListEmail = (new Date()).toISOString();

if ( ctx.currentBlackList.@blackListEmail != ctx.recipient.@blackListEmail ) {
xtk.session.Write(ctx.recipient)
}

}

 

Regards,

Milan

 

1 reply

Milan_Vucetic
Milan_VuceticAccepted solution
Level 9
February 29, 2020

Hi @raulocana ,

 

recipient table has a native link to Modified by where datetime is updated when any field is changed.

In case you need a new column you can define a new attribute/column like this and field will contain sysdate when record was inserted (Oracle).

 

If you are using web app (for email opt in/out) you can use JS like this:

 

if ( ctx.vars.recipientId == "" || ctx.vars.recipientId == undefined || ctx.vars.recipientId == null ) {

ctx.recipient.@xtkschema="nms:recipient";
ctx.recipient.@_operation="update";
ctx.recipient.@_key="@id";
ctx.recipient.@lastBlackListEmail = (new Date()).toISOString();

if ( ctx.currentBlackList.@blackListEmail != ctx.recipient.@blackListEmail ) {
xtk.session.Write(ctx.recipient)
}

}

 

Regards,

Milan

 

RaulOcana
RaulOcanaAuthor
Level 3
March 6, 2020
thank you, it works